Prevent/Disable BottomSheetScaffold from being swiped/dragged
Asked Answered
W

2

6

I have a BottomSheetScaffold(), on button push the bottomsheet is coming up, all is working fine, but i want to prevent the user from swiping down the bottomsheet. Instead a button on the bottomsheet is use to close it on click.

I see the option drawerGesturesEnabled, but this not doing anything.

Wickerwork answered 18/11, 2022 at 12:30 Comment(0)
V
2

You can set its sheetGesturesEnabled parameter to false

BottomSheetScaffold(
    sheetGesturesEnabled = false,
    …
    …
Votaw answered 18/11, 2022 at 14:46 Comment(0)
T
1

The code above works as long as there is no scrollable content inside.

I had a task to prevent the BottomSheet collapsing by swiping down (or rather, in the process of scrolling nested content). Here is the solution I found (use confirmStateChange callback). I hope this will be useful to someone.

val scaffoldState = rememberBottomSheetScaffoldState(
    bottomSheetState = rememberBottomSheetState(
        initialValue = BottomSheetValue.Collapsed,
        confirmStateChange = {
            // Prevent collapsing by swipe down gesture
            it != BottomSheetValue.Collapsed
        }
    ),
    snackbarHostState = remember { SnackbarHostState() }
)
Themistocles answered 1/3, 2023 at 22:34 Comment(1)
Your solution seems incomplete, please elaborate.Mozell

© 2022 - 2024 — McMap. All rights reserved.