react-native-bottom-sheet icon indicating copy to clipboard operation
react-native-bottom-sheet copied to clipboard

Fix BottomSheet closing instantly when snapPoints change

Open Maniae opened this issue 1 year ago • 3 comments

Please provide enough information so that others can review your pull request:

Motivation

Probably related to https://github.com/gorhom/react-native-bottom-sheet/issues/1053

When snapPoints of a bottom sheet change while its animating, it may close it in some situations. After some investigation, I think the reason for that is the animatedReaction on snapPoints/containerHeight that closes the bottom sheet under these conditions : animatedCurrentIndex.value === -1

The problem being in some cases, when animation complete, the snapPoints change reaction seems to be called right after the completion callback, before any reaction on the animatedPosition. Since the the animatedPosition reaction is the one setting the animatedCurrentIndex value, this old value is used and causes the closing of the bottom sheet.

~~This fix is a simple line on the completion callback, setting the animatedCurrentIndex value to its goal value.~~ The previous fix caused an issue where the onChange callback would not fire anymore.

A better fix is to handle the case were the animation is STOPPPED in the snapPoints change listener, and set the new position using the actual animatedIndex value.

Maniae avatar Apr 25 '24 16:04 Maniae

I think it's a good idea. Probably it will also fix issues with enableDymanicSizing resize

https://github.com/gorhom/react-native-bottom-sheet/assets/57757211/01a33a59-37ad-4c9a-8534-d6c696420bb4

XantreDev avatar May 01 '24 12:05 XantreDev

Hey, do you know if it's going to be released soon in V4 ?

theohdv avatar May 22 '24 12:05 theohdv

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Jun 22 '24 09:06 github-actions[bot]

why closed? but is still appear

ryskin avatar Jul 08 '24 10:07 ryskin

Because of the genius bot

XantreDev avatar Jul 08 '24 16:07 XantreDev

after snapToPosition i set a timeout for 3 seconds before trying to set new snapPoints, this however caused the sheet to close. would that be a separate issue from this? My sense was that the animation was complete before I attempted to set the snap points so it would've been fine but that doesn't seem to be the case

2ndMostGlossy avatar Jul 22 '24 13:07 2ndMostGlossy