How to interrupt sheet dismissal #1061
Replies: 4 comments 7 replies
-
Personally, I'd probably set enablePanDownToClose prop to false, use the onAnimate prop to determine if the user swiped down to index 0 (since -1 is not allowed) and show the prompt when this happens. If the user cancels don't do anything, but if the user confirms the prompt then close the bottom sheet using ref method close().
Hope this helps! I did it on my phone, so there may be errors. 😊 - Logan (a.k.a. DarkComet) |
Beta Was this translation helpful? Give feedback.
-
I also don't get this to work, how can we interrupt the backdrop click and pan down? |
Beta Was this translation helpful? Give feedback.
-
I needed this same behavior, and I think I was experiencing the same bugs and glitches that you both describe. My use case was to be able to have an onRequestClose handler step in between user close interaction, and actual closing of the sheet. The way I fixed it was to introduce a new pressBehavior "override" to the backdrop, which lets you define your own onPress handler, without press of the backdrop triggering any of the default behaviors. I ended up using the onClose handler on BottomSheet to listen for sheet close. I intend to suggest this in a pull request when I get the time. You can patch version 4.4.5 with patch-package using this until then: @gorhom+bottom-sheet+4.4.5.patch
|
Beta Was this translation helpful? Give feedback.
-
I managed a simple solution to invoke the handleModalPress() on an index of -1. It has the benefit of letting the user swipe down (to still indicate it is a sheet, from a UX perspective. But then it springs back up again with an elastic motion). Just modify the getting started code.
...
|
Beta Was this translation helpful? Give feedback.
-
Use case: I'm displaying a form in a bottom sheet. If the user has entered any data, a prompt should be displayed to the user before closing the sheet and clearing the form data. So if the user taps on the backdrop or swipes the bottom sheet away, I want to keep the sheet open and change the bottom sheet contents to an "are you sure" prompt.
My current approach is to add an
onAnimate
handler, check theto
index, and callexpand()
on the bottom sheet instance to force it back to the open state. This works for swiping the bottom sheet, but doesn't work for taps on the backdrop. Tapping the backdrop seems a little buggy when doing this too. Sometimes it will stay open, but other times it will close.Beta Was this translation helpful? Give feedback.
All reactions