react-native-bottom-sheet
react-native-bottom-sheet copied to clipboard
Fix BottomSheet closing instantly when snapPoints change
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.
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
Hey, do you know if it's going to be released soon in V4 ?
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.
why closed? but is still appear
Because of the genius bot
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