google / accompanist

A collection of extension libraries for Jetpack Compose
https://google.github.io/accompanist
Apache License 2.0
7.43k stars 598 forks source link

[Navigation Material] App crashes on launch - confirmStateChange is null #1577

Closed jollygreenegiant closed 1 year ago

jollygreenegiant commented 1 year ago

Description I'm getting the following crash on launch when calling rememberBottomSheetNavigator() - code shown in steps to reproduce:

Crash logs:

java.lang.NullPointerException: Parameter specified as non-null is null: method androidx.compose.material.ModalBottomSheetKt.rememberModalBottomSheetState, parameter confirmStateChange
    at androidx.compose.material.ModalBottomSheetKt.rememberModalBottomSheetState(Unknown Source:9)
    at com.google.accompanist.navigation.material.BottomSheetNavigatorKt.rememberBottomSheetNavigator(BottomSheetNavigator.kt:107)
    at com.jggdevelopment.bookbuddy.android.MainActivity$onCreate$1.invoke(MainActivity.kt:135)
    at com.jggdevelopment.bookbuddy.android.MainActivity$onCreate$1.invoke(MainActivity.kt:134)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
    at androidx.compose.ui.platform.ComposeView.Content(ComposeView.android.kt:428)
    at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:252)
    at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:251)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
    at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:194)
    at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:123)
    at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:122)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
    at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.ProvideAndroidCompositionLocals(AndroidCompositionLocals.android.kt:114)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$2.invoke(Wrapper.android.kt:156)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$2.invoke(Wrapper.android.kt:155)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:155)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:140)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
    at androidx.compose.runtime.ActualJvm_jvmKt.invokeComposable(ActualJvm.jvm.kt:78)
    at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3352)
    at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3342)
    at androidx.compose.runtime.SnapshotStateKt__DerivedStateKt.observeDerivedStateRecalculations(DerivedState.kt:341)
    at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(Unknown Source:1)
    at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3342)
    at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:3277)
    at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:587)
    at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:966)

Steps to reproduce

setContent {
    val bottomSheetNavigator = rememberBottomSheetNavigator() <----- Crash here
    val navController = rememberAnimatedNavController(bottomSheetNavigator)

    Surface(
        color = MaterialTheme.colorScheme.background,
        modifier = Modifier.fillMaxSize()
    ) {
        ModalBottomSheetLayout(bottomSheetNavigator) {
            Scaffold {
                AnimatedNavHost()
            }
        }
    }
}

Expected behavior App should not crash

Additional context I have no idea what could be causing this, since I'm just calling the standard method, which defines a default implementation for the parameter that the crash is saying is null. Not really sure where to go from here.

Khaled-Eldeeb-BW commented 1 year ago

Update accompanist version to 0.31.0-alpha

jollygreenegiant commented 1 year ago

@AhmedNader7 updated, and still seeing the issue

jollygreenegiant commented 1 year ago

Apologies, I updated the wrong dependency - updating to 0.31.0-alpha seems to have fixed the problem

bentrengrove commented 1 year ago

I assume that means you are using the Compose alphas as well. Either make sure you are only using Compose 1.4 stable versions and the accompanying accompanist version, or use the accompanist version to match Compose 1.5 which is 0.31.x

SakhiMahanag commented 1 year ago

Facing the same crash with compose - 1.5.0-beta03 and accompanist - 0.31.3-beta. Any one has any idea on how to solve this?