简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM