Hey folks, does anyone have any information on why...
# compose
n
Hey folks, does anyone have any information on why I might be having a crash at runtime with a ModalBottomSheetLayout only on a tablet device? readout in ­čžÁ
Copy code
java.lang.IllegalArgumentException: The initial value must have an associated anchor.
        at androidx.compose.material.SwipeableState.ensureInit$material_release(Swipeable.kt:138)
        at androidx.compose.material.SwipeableKt$swipeable$3.invoke(Swipeable.kt:594)
        at androidx.compose.material.SwipeableKt$swipeable$3.invoke(Swipeable.kt:573)
        at androidx.compose.ui.ComposedModifierKt$materialize$result$1.invoke(ComposedModifier.kt:73)
        at androidx.compose.ui.ComposedModifierKt$materialize$result$1.invoke(ComposedModifier.kt:68)
        at androidx.compose.ui.Modifier$Element$DefaultImpls.foldIn(Modifier.kt:107)
        at androidx.compose.ui.ComposedModifier.foldIn(ComposedModifier.kt:46)
        at androidx.compose.ui.CombinedModifier.foldIn(Modifier.kt:149)
        at androidx.compose.ui.CombinedModifier.foldIn(Modifier.kt:149)
        at androidx.compose.ui.CombinedModifier.foldIn(Modifier.kt:149)
        at androidx.compose.ui.CombinedModifier.foldIn(Modifier.kt:149)
        at androidx.compose.ui.CombinedModifier.foldIn(Modifier.kt:149)
        at androidx.compose.ui.CombinedModifier.foldIn(Modifier.kt:149)
        at androidx.compose.ui.CombinedModifier.foldIn(Modifier.kt:149)
        at androidx.compose.ui.CombinedModifier.foldIn(Modifier.kt:149)
        at androidx.compose.ui.CombinedModifier.foldIn(Modifier.kt:149)
        at androidx.compose.ui.ComposedModifierKt.materialize(ComposedModifier.kt:68)
        at androidx.compose.ui.layout.LayoutKt$materializerOf$1.invoke-Deg8D_g(Layout.kt:221)
        at androidx.compose.ui.layout.LayoutKt$materializerOf$1.invoke(Layout.kt:220)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:116)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.material.SurfaceKt$Surface$6.invoke(Surface.kt:299)
        at androidx.compose.material.SurfaceKt$Surface$6.invoke(Surface.kt:254)
        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.material.SurfaceKt.Surface-F-jzlyU(Surface.kt:251)
        at androidx.compose.material.SurfaceKt.Surface-F-jzlyU(Surface.kt:110)
        at androidx.compose.material.ModalBottomSheetKt$ModalBottomSheetLayout$1.invoke(ModalBottomSheet.kt:262)
This is on
material:1.0.5
i
That error usually means you didn't actually output any composables into your bottom sheet when it is first created (i.e., it has zero height in that first pass)
n
Copy code
@OptIn(ExperimentalMaterialApi::class, ExperimentalFoundationApi::class)
@Composable
fun ModalTabletCrashingComposable() {
    val modalBottomSheetState = rememberModalBottomSheetState(initialValue = ModalBottomSheetValue.Hidden)
    ModalBottomSheetLayout(
        modifier = Modifier.fillMaxSize(),
        sheetContent = {
            Text(text = "Sheet Content")
        },
        sheetShape = RoundedCornerShape(CornerSize(16.dp)),
        sheetState = modalBottomSheetState,
        scrimColor = Color.Unspecified
    ) {
        Text(text = "Page Content")
    }
}
This Composable crashes instantly on Pixel C API 31
i
Sounds like you have the makings of a good sample project you could attach to an issue: https://issuetracker.google.com/issues/new?component=742043