I'm having a strange bug, when I try to show Botto...
# compose
m
I'm having a strange bug, when I try to show BottomSheet using
BottomSheetScaffold
it closes right away
Copy code
BottomSheetScaffold(
                scaffoldState = bottomSheetScaffoldState,
                sheetContent = {
                    LazyColumn {
                        items(count = 10) {
                            Text(
                                text = "Item $it",
                                modifier = Modifier.padding(vertical = 8.dp)
                            )
                        }
                    }
                },
            ) {
                Box(
                    modifier = Modifier.fillMaxSize().padding(it),
                    contentAlignment = Alignment.Center
                ) {
                    Button(
                        onClick = {
                            coroutineScope.launch {
                                bottomSheetScaffoldState.bottomSheetState.expand()
                            }
                        },
                    ) {
                        Text(text = "Open sheet")
                    }
                }
            }
a
How are you creating your
bottomSheetScaffoldState
?
And please put the long code snippet into the thread.
m
yeah.
Copy code
rememberBottomSheetScaffoldState(
    bottomSheetState = BottomSheetState(BottomSheetValue.Collapsed),
)
a
You are not remembering the
BottomSheetState
so it is a new instance on every recomposition. Use
rememberBottomSheetState
.
m
ahh... yes, I forgot to remember after refactoring, thanks !!
@Albert Chang
ModalBottomSheetLayout
has a scrimColor whereas
BottomSheetScaffold
don't How to add a scrimColor to BottomSheetScaffold?
a
The scrim color tells the user that the rest of the screen can't be interacted with.
BottomSheetScaffold
allows interaction with the rest of the screen so scrim color shouldn't be used. If you want to block interaction, just use
ModalBottomSheetLayout
.