accompanist icon indicating copy to clipboard operation
accompanist copied to clipboard

Provide a method to make the bottom sheet non-cancellable for some use-cases.

Open dilraj-singh1997 opened this issue 3 years ago • 18 comments

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]

dilraj-singh1997 avatar Sep 17 '21 14:09 dilraj-singh1997

@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

ravitejasc avatar Sep 17 '21 15:09 ravitejasc

@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.

jossiwolf avatar Sep 18 '21 19:09 jossiwolf

Thanks for the quick reply @jossiwolf.

dilraj-singh1997 avatar Sep 18 '21 19:09 dilraj-singh1997

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.

github-actions[bot] avatar Oct 19 '21 03:10 github-actions[bot]

@jossiwolf please remove the stale label if you are planning on implementing this. Thanks.

dilraj-singh1997 avatar Oct 19 '21 06:10 dilraj-singh1997

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.

github-actions[bot] avatar Nov 19 '21 03:11 github-actions[bot]

Any update on this ?

knightsamir avatar Jan 11 '22 07:01 knightsamir

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.

github-actions[bot] avatar Feb 11 '22 03:02 github-actions[bot]

Not stale

micHar avatar Feb 11 '22 06:02 micHar

Any update on this?

hiteshchopra11 avatar May 06 '22 08:05 hiteshchopra11

Any update on this?

dimitriz09 avatar Oct 25 '22 10:10 dimitriz09

@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
    )

hiteshchopra11 avatar Oct 25 '22 12:10 hiteshchopra11

" 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

amitrandhawa1 avatar Apr 25 '23 04:04 amitrandhawa1

Great with a PR for this issue!

Any update to the state of the PR?

mortenholmgaard avatar Jun 06 '23 06:06 mortenholmgaard

@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 ?

UKMIITB avatar Oct 06 '23 15:10 UKMIITB

@jossiwolf Any update here

UKMIITB avatar Oct 10 '23 09:10 UKMIITB

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.

amanv8060 avatar Oct 13 '23 11:10 amanv8060

Any updates??

sidbamba avatar Oct 26 '23 05:10 sidbamba