skydoves / Cloudy

☁️ Jetpack Compose blur effect library, which falls back onto a CPU-based implementation to support older API levels.
Apache License 2.0
789 stars 28 forks source link

Context casting #1

Closed WoodyMKD closed 1 year ago

WoodyMKD commented 1 year ago

Describe the Bug:

The application crashes with the following exception:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.datarella.mobix, PID: 9337
    java.lang.ClassCastException: dagger.hilt.android.internal.managers.ViewComponentManager$FragmentContextWrapper cannot be cast to android.app.Activity
        at com.skydoves.cloudy.CloudyKt$cloudy$7.invoke(Cloudy.kt:185)
        at com.skydoves.cloudy.CloudyKt$cloudy$7.invoke(Cloudy.kt:179)
        at androidx.compose.ui.ComposedModifierKt$materialize$result$1.invoke(ComposedModifier.kt:278)
        at androidx.compose.ui.ComposedModifierKt$materialize$result$1.invoke(ComposedModifier.kt:273)
        at androidx.compose.ui.Modifier$Element.foldIn(Modifier.kt:114)
        at androidx.compose.ui.CombinedModifier.foldIn(Modifier.kt:272)
        at androidx.compose.ui.ComposedModifierKt.materialize(ComposedModifier.kt:273)
        at androidx.compose.ui.layout.LayoutKt$materializerOf$1.invoke-Deg8D_g(Layout.kt:193)
        at androidx.compose.ui.layout.LayoutKt$materializerOf$1.invoke(Layout.kt:192)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:116)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at com.skydoves.cloudy.CloudyKt$composeCloudy$1$1.invoke(Cloudy.kt:335)
        at com.skydoves.cloudy.CloudyKt$composeCloudy$1$1.invoke(Cloudy.kt:127)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)

Apparently, this happens when using Hilt: https://stackoverflow.com/questions/64341415/dagger-hilt-android-internal-managers-viewcomponentmanagerfragmentcontextwrappe

The line causing the error: val window = (LocalContext.current as Activity).window

skydoves commented 1 year ago

Hey @WoodyMKD, thanks for reporting this issue. But this issue should be to be reported on Dagger's repository. But let me check if there are other ways to resolve this issue in this library. Thanks!

myounisWajeez commented 1 year ago

@skydoves Thanks for the super fast fix <3