disable click outside dismiss on a material 3 jetpack compose ModalBottomSheet

1.6k Views Asked by At

is there any way i can disable this built in behaviour of dissmissal of the Material 3 bottomsheet after any click outside the half expanded bottom sheet

   ModalBottomSheet(
    onDismissRequest = { },// i'd like to ignore this property,handle dissmissal myself
    sheetState = bottomSheetState,
    tonalElevation = MagicUnit.mu025,
    dragHandle = {},
) 

is there any suggestion to apply ?

2

There are 2 best solutions below

0
On

You can use the confirmValueChange parameter for more control or disabling it.

ModalBottomSheet(
    onDismissRequest = { /*Do nothing*/ },
    sheetState = rememberModalBottomSheetState(
        confirmValueChange = { 
            if (condition) true else false
        }
    ),
) { /* content */}
0
On

I don't know about ModalBottomSheet composable but in BottomSheetScaffold there is a parameter flag named sheetGesturesEnabled we can toggle it to false to disable the user actions outside of the BottomSheet