'Jetpack Compose BottomSheetScaffold sheetGestures disabled but gestures still works when child component is scrollable

I have a BottomSheetScaffold inside my android app that looks like the following:

 BottomSheetScaffold(
        sheetGesturesEnabled = false,
        sheetContent = { MyContent() },
        scaffoldState = bottomSheetScaffoldState,
    ) {
        ..
    }

With the sheetGesturesEnabled set to false, the sheet should not be swipeable. However, if MyContent() contains a scrollable component like LazyColumn, the swipe to close gesture can still be executed on the modal bottom sheet.

How is that possible? Is that a known bug? Is there any fix to this?



Solution 1:[1]

Looks like this is a known bug and can be tracked here -> https://issuetracker.google.com/issues/215403277

I also ran into this and needed to find a solve in the meantime so I ended up setting the sheetPeekHeight to the height of my LazyColumn. Please note, I am not proud of this.

  BottomSheetScaffold(
        scaffoldState = sheetState,
        sheetGesturesEnabled = false,
        sheetPeekHeight = if(isFixedHeight) 500.dp else BottomSheetScaffoldDefaults.SheetPeekHeight,
        sheetContent = {

           LazyColumn(
               state = listState,
               userScrollEnabled = true,
                modifier = Modifier
                .heightIn(max = 500.dp)
                ) { //items }
           }
         

In my implementation, I set the sheetPeekHeight conditionally because in only some cases would it need to be static and others it wouldn't.

Its not pretty but it works. I'm sure other workarounds exist but this one fit my use case the best. Just be sure to add a TODO to fix it once there is a fix for the bug published.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Karli Niemann