fix: Default animatedNextPositionIndex to INITIAL_VALUE #1960
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
This fix is very similar to #1035 and #1043
BottomSheet will sometimes not animate/expand because of this logic. This can happen when you have a single
snapPoint
, or if you useenableDynamicSizing
.Issue
animatedNextPositionIndex
starts at 0, which is the same assnapPoints.length -1
, causing the animation to be aborted.Starting values:
react-native-bottom-sheet/src/components/bottomSheet/BottomSheet.tsx
Lines 239 to 240 in b6e405b
After a successful animation, it is reset correctly to the right value:
Reset values:
react-native-bottom-sheet/src/components/bottomSheet/BottomSheet.tsx
Lines 647 to 648 in b6e405b
It should always start at
INITIAL_VALUE
(-Infinity) likeanimatedNextPosition
.Reproducing
Note: this isn't always reproducible for me. I have two identical BottomSheets, and only one of them is broken. Something in the working one is resetting the
animatedNextPositionIndex.value
to-Infinity
before the animation runs, but I'm struggling to debug where that's happening.