Hello! Any clue on why my bottom sheet is showing ...
# compose
m
Hello! Any clue on why my bottom sheet is showing when I set Hidden as the initialValue of the state?
Copy code
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
            bottomSheetState =

            rememberStandardBottomSheetState(
                initialValue = SheetValue.Hidden,
                skipHiddenState = false
            )
        )
       BottomSheetScaffold(
            scaffoldState = bottomSheetScaffoldState,
            sheetPeekHeight = INFO_SHEET_PEEK_HEIGHT,
            sheetContent = { JobInfoSheet(jobInfoSlice = form.value.jobInfoSlice) }) {
            ... content
    }
s
Yes, you’re probably using M3 bottom sheet? I fell into the same trap. Although we have the SheetState with
show()
and
hide()
, you also need to wrap the ModalBottomSheet in an
if
condition or it will always show and when you call
hide()
without the
if
condition, it will be invisible but still block any interaction with the UI. Also see the example code here. Since I didn’t want to have an additional state I wrote an extension function for
SheetState
Copy code
@ExperimentalMaterial3Api
val SheetState.shouldShowModalBottomSheet
    get() = isVisible || targetValue == SheetValue.Expanded
and then I use it in Compose like
Copy code
if (sheetState.shouldShowModalBottomSheet) {
  ModalBottomSheet(
    ...
  )
}
m
Ah thats annoying but I'll guess I have to do something similar. Thanks!
👍🏼 1
s
You might have to adjust the extension function because I don’t use
SheetValue.PartiallyExpanded
109 Views