joghm
joghm

Reputation: 718

disable click outside dismiss on a material 3 jetpack compose ModalBottomSheet

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 ?

Upvotes: 4

Views: 5278

Answers (5)

Saif Ur Rehman
Saif Ur Rehman

Reputation: 31

ModalBottomSheet(
        onDismissRequest = onDismiss,
        sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true) { it != SheetValue.Hidden },
        containerColor = colorResource(id = R.color.navigation_back),
        properties = ModalBottomSheetProperties(
            securePolicy = SecureFlagPolicy.SecureOn,
            shouldDismissOnBackPress = true
        )
    ) 
try this it fixed not freeze the UI also

Upvotes: 0

Edhar Khimich
Edhar Khimich

Reputation: 1674

Here how it works for me:

val bottomSheetState =
        rememberModalBottomSheetState(skipPartiallyExpanded = true, confirmValueChange = { newState ->
            newState != SheetValue.Hidden //  Stop bottom sheet from hiding on outside press
        })

Upvotes: 3

RImanuelSundar
RImanuelSundar

Reputation: 21

iI don't know, if i leave onDismissRequest = { } as empty then my app got freeze. Even back navigation is not working.

Upvotes: 0

ilkek
ilkek

Reputation: 264

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 */}

Upvotes: 7

zaid khan
zaid khan

Reputation: 1012

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

Upvotes: 0

Related Questions