accompanist
accompanist copied to clipboard
Provide a method to make the bottom sheet non-cancellable for some use-cases.
Describe the bug
Provide a method to make the bottom sheet non-cancellable for some use-cases.
Expected behaviour
When a user clicks the back button or the outside content of the bottom sheet, then it dismisses. However, there should be a way to control that behaviour based on a flag that the bottom sheet should not dismiss. It should only dismiss via calling navGraph.navigateBack()
.
Environment:
- Android OS version: [Android 11.0]
- Device: [Samsung M20]
- Accompanist version: [0.17.0]
@OptIn(ExperimentalMaterialNavigationApi::class, ExperimentalMaterialApi::class)
@Composable
fun rememberBottomSheetNavigator(
animationSpec: AnimationSpec<Float> = SwipeableDefaults.AnimationSpec,
confirmStateChange: (ModalBottomSheetValue) -> Boolean = { true }
): BottomSheetNavigator {
val sheetState = rememberModalBottomSheetState(
ModalBottomSheetValue.Hidden,
animationSpec, confirmStateChange
)
return remember(sheetState) {
BottomSheetNavigator(sheetState = sheetState)
}
}
try this, toggle confirmStateChange
as per your use case
@dilraj-singh1997 Thanks for the feature request. The bottom sheet will always be dismissed when the associated destination is popped of the back stack (such as is the case when going back). I will look into exposing a flag that mirrors ModalBottomSheetLayout'
s gesturesEnabled
flag to disable dismissal by touching outside of the sheet.
@ravitejasc Please don't do this - BottomSheetNavigator
relies on implementation details of ModalBottomSheetState
to work. Overriding confirmStateChange
does not guarantee this to work and is a good way to get the navigator out of sync. This constructor of BottomSheetNavigator
might be made internal
in the future.
Thanks for the quick reply @jossiwolf.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
@jossiwolf please remove the stale label if you are planning on implementing this. Thanks.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
Any update on this ?
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
Not stale
Any update on this?
Any update on this?
@dimitriz09 As a workaround, I
returned false in confirmStateChange
of rememberModalBottomSheetState
and it worked for me.
val confirmStateChange: (ModalBottomSheetValue) -> Boolean = remember {
{ false }
}
val sheetState = rememberModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden,
animationSpec = SwipeableDefaults.AnimationSpec,
confirmStateChange = confirmStateChange
)
" I will look into exposing a flag that mirrors ModalBottomSheetLayout's gesturesEnabled flag to disable dismissal by touching outside of the sheet."
Any update on this @dimitriz09 @jossiwolf @dilraj-singh1997
Great with a PR for this issue!
Any update to the state of the PR?
@jossiwolf Is there an update on this issue or on this PR https://github.com/google/accompanist/pull/1642
@jossiwolf Can you suggest any temporary workaround for this ?
@jossiwolf Any update here
I think the system back could be handled by BackHandler, and the swipe could be handled using this PR: https://github.com/google/accompanist/pull/1642.
Any updates??