accompanist icon indicating copy to clipboard operation
accompanist copied to clipboard

[Idea] Add parameter to disableclose by swiping down on BottomSheetNavigator by default

Open TanoAirthings opened this issue 3 years ago • 30 comments

Is your feature request related to a problem? Please describe. My purpose is to avoid the bottomSheet to be closed by dragging it down. Inside our BottomSheet we have a scrollable list. When the user scrolls back to the top, the component will close. We want to avoid this behaviour.

Describe the solution you'd like I'd like to dismiss the bottom sheet by just tapping outside. For this purpose I'd like to be able to use a composable function (or a parameter to pass to the constructor) to switch on or off the draggability of the bottom sheet.

Describe alternatives you've considered We tried to use a BottomSheetScaffold but we don't know where in the code should be placed. We also tried to take a look at the parameters that modifies the internal behaviour of the ModalBottomSheetLayout but the internal scaffold seems not to have the sheetGesturesEnabled or isSwipable or isDraggable boolean we were looking for.

We found a sheetGesturesEnabled inside the BottomSheetScaffold object, but, as I said, we didn't find a proper way to implement it.

Thanks for you time.

TanoAirthings avatar Apr 26 '22 16:04 TanoAirthings

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 May 28 '22 03:05 github-actions[bot]

@jossiwolf We're still waiting for info

TanoAirthings avatar May 30 '22 07:05 TanoAirthings

I have the same issue. Swiping down is too sensitive and closes bottom sheet almost instantly if there is scrollable content inside. But I would prefer to have exposed param per-destination for that, not the global one.

agent10 avatar Jun 07 '22 09:06 agent10

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 Jul 08 '22 03:07 github-actions[bot]

@jossiwolf It is still the issue.

agent10 avatar Jul 08 '22 03:07 agent10

@jbw0033 @jossiwolf is it possible to have any kind of reply on this?

TanoAirthings avatar Jul 26 '22 07:07 TanoAirthings

We need this feature as well. 👍

MarcLFJ avatar Aug 24 '22 07:08 MarcLFJ

I think it's an important feature to be able to prevent a user from dragging down or dismissing a bottom sheet. It's possible to disable the dragging/dismissing in SWIFT for iOS, and the feature should also exist for Jetpack Compose.

We need the functionality for the project I am working on as well.

lilemma avatar Aug 26 '22 07:08 lilemma

Same for me

riegersan avatar Sep 06 '22 07:09 riegersan

My Team and I have found a workaround.

We have set a Box around our bottom sheet and added this to the modifier.

.pointerInput(Unit) { awaitPointerEventScope { // we should wait for all new pointer events while (true) { awaitPointerEvent(pass = PointerEventPass.Initial) .changes .forEach(PointerInputChange::consumePositionChange) } } },

To prevent a closing of the sheet when the user presses above the sheet we set the hight to full screen hight.

I know, it's a ugly workaround but the best we have found currently.

riegersan avatar Sep 06 '22 08:09 riegersan

My Team and I have found a workaround.

We have set a Box around our bottom sheet and added this to the modifier.

.pointerInput(Unit) { awaitPointerEventScope { // we should wait for all new pointer events while (true) { awaitPointerEvent(pass = PointerEventPass.Initial) .changes .forEach(PointerInputChange::consumePositionChange) } } },

To prevent a closing of the sheet when the user presses above the sheet we set the hight to full screen hight.

I know, it's a ugly workaround but the best we have found currently.

I can't get your code to work unfortunately.

Where would you put that code, if you're using the NavGraphBuilder.bottomSheet? A box around it is not possible, since the NavGraphBuilder is not a @Composable function.

lilemma avatar Sep 16 '22 09:09 lilemma

Please see https://issuetracker.google.com/issues/186669832 for the upstream issue. Unfortunately, this is blocked until we have it upstream. We will be working on this in the near future, but there are some other dependencies we need to resolve first. @riegersan's workaround should work for touch input, but doesn't consider a11y (that'd be a lot to ask for a workaround!). Sorry about the delay everyone, I too wish we could speed it up :)

jossiwolf avatar Sep 23 '22 15:09 jossiwolf

My Team and I have found a workaround.

We have set a Box around our bottom sheet and added this to the modifier.

.pointerInput(Unit) { awaitPointerEventScope { // we should wait for all new pointer events while (true) { awaitPointerEvent(pass = PointerEventPass.Initial) .changes .forEach(PointerInputChange::consumePositionChange) } } },

To prevent a closing of the sheet when the user presses above the sheet we set the hight to full screen hight.

I know, it's a ugly workaround but the best we have found currently.

Just a heads up, this workaround disables all interactive content hosted in your sheet as well. So for example, if your bottom sheet has buttons, then a user won't be able to tap them.

trod-123 avatar Jan 20 '23 22:01 trod-123

Same for me. Really need it. Is there any ideas for temporary solution for this problem?

Monabr avatar Feb 10 '23 02:02 Monabr

I found this code. Maybe we could modify this code so it enables inner scrolling but still disables bottom sheet scrolling?

fun Modifier.verticalScrollDisabled() =
    pointerInput(Unit) {
        awaitPointerEventScope {
            while (true) {
                awaitPointerEvent(pass = PointerEventPass.Initial).changes.forEach {
                    val offset = it.positionChange()
                    if (abs(offset.y) > 0f) {
                        it.consume()
                    }
                }
            }
        }
    }

Monabr avatar Feb 10 '23 03:02 Monabr

@jossiwolf this repo https://github.com/SmartToolFactory/Jetpack-Compose-Tutorials in screen 2-10-1 https://github.com/SmartToolFactory/Jetpack-Compose-Tutorials#2-10-1-bottomsheet does not have this problem. After content started scrolled and scrolled back to the top - bottom sheet does not collapse.

Monabr avatar Feb 10 '23 14:02 Monabr

Hi everyone. Here is my solution (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() }
    )

reminmax avatar Mar 01 '23 22:03 reminmax

Hello @jossiwolf ,

I hope you're doing well. I wanted to bring up a concern about the bottom sheets functionality. From my perspective, it feels like the prioritization of this feature is lagging behind, and it's important to have it available. I'm wondering if you're overloaded with work or if there are other factors that are preventing progress on this issue.

As a developer relying on accompanist, it's frustrating to see multiple issues and requested features for bottom sheets with no progress or indication of when they will be looked into. I believe that many others feel the same way.

With that in mind, I would like to include some other contributors in this comment so that we can amplify our voices and work together to ensure that this feature receives the attention it deserves. Thank you for your time. @chrisbanes @bentrengrove @JoseAlcerreca @alexvanyo @manuelvicnt @nickbutcher @andkulikov @fornewid @riggaroo @svenjacobs @sampengilly @jbw0033 @CaptnBlubber

lilemma avatar Mar 27 '23 08:03 lilemma

As Jossi mentioned above, we are waiting on a proper API for this to be added to Compose upstream. Work on Accompanist is done on a best effort basis and work on the main Compose libraries comes first. We happily accept contributions if someone else can implement this.

Mass tagging contributors as above is not appropriate and could lead to being banned from commenting in the future.

bentrengrove avatar Mar 27 '23 09:03 bentrengrove

In addition to Ben's comment, we are not only happy to accept contributions for Accompanist but also accept contributions to Compose as it is a part of the Android Open Source Project.

There are three work items needed for this issue:

  1. Add the parameter upstream
  2. Figure out per-destination flags like skipHalfExpanded and gesturesEnabled, which needs careful architecting because of recomposition timing
  3. Implement the gesturesEnabled flag

Feel free to ping us directly on channels like KotlinLang if you are interested in contributing this upstream and here!

jossiwolf avatar Mar 27 '23 09:03 jossiwolf

I don't agree with the mass tagging, but the 'best effort' stuff is a bit of a cop-out. Either the library is supported or not. If it's not supported, it should be deprecated as such.

chrisbanes avatar Mar 27 '23 09:03 chrisbanes

Best effort may not have been the right term here. Accompanist is actively supported, in this case we have just had to prioritise other work first for bottom sheets in the main Compose libraries. This issue is blocked until we can get that work done upstream.

bentrengrove avatar Mar 28 '23 00:03 bentrengrove

Hi everyone. Here is my solution (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() }
    )

@reminmax Just to confirm, with this setting the sheet will still "slide" down but then return to the top position? Thats what I see, it works but a little more janky than the intention

DaveSeverns avatar May 19 '23 12:05 DaveSeverns

Hi everyone. Here is my solution (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() }
    )

@reminmax Just to confirm, with this setting the sheet will still "slide" down but then return to the top position? Thats what I see, it works but a little more janky than the intention

Yes. The sheet will still "slide" down but then return to the top position. In other words, this prevents closing the BottomSheet.

reminmax avatar May 19 '23 13:05 reminmax

@jossiwolf The upstream issue is marked as fixed https://github.com/google/accompanist/issues/1142

Is it possible to relook into having it for bottom sheet navigator now

UKMIITB avatar Oct 06 '23 15:10 UKMIITB

@jossiwolf Any update here

UKMIITB avatar Oct 10 '23 09:10 UKMIITB

@jossiwolf any updates?

sidbamba avatar Oct 26 '23 05:10 sidbamba

any updates?

DikenMaharjan avatar Nov 16 '23 04:11 DikenMaharjan

Updates?

StringMeUp avatar Nov 24 '23 13:11 StringMeUp

They apparently solved the issue, but I didn't understand the solution. Anyone care to explain? https://issuetracker.google.com/issues/215403277#comment11

DoraswamyVamsi avatar Dec 01 '23 12:12 DoraswamyVamsi