fix: sanitize velocity to prevent instant snap on Reanimated v4+#2657
Open
ahmadaccino wants to merge 1 commit into
Open
fix: sanitize velocity to prevent instant snap on Reanimated v4+#2657ahmadaccino wants to merge 1 commit into
ahmadaccino wants to merge 1 commit into
Conversation
…hom#2470) Reanimated v4 + Gesture Handler v2 can report an excessively high velocityY in the opposite direction of the snap target. When passed directly to withSpring, the spring overshoots and resolves in a single frame — producing an instant snap with no visible animation. Fix: - Clamp velocity magnitude to ±500 - Zero velocity when it opposes the snap direction These guards are safe for all Reanimated versions since large opposing velocities are never desirable for snap animations. Fixes gorhom#2470
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #2470 — no smooth animation when the bottom sheet snaps back to its initial position on Reanimated v4 + Gesture Handler v2.
Root Cause
Reanimated v4 + Gesture Handler v2 can report an excessively high
velocityYwhose direction is opposite to the snap target. When this velocity is passed directly towithSpring, the spring overshoots and resolves in a single frame — producing an instant snap with no visible animation.Fix
Two guards are applied to the velocity inside
animateToPositionbefore it reacheswithSpring:Why this is safe for all Reanimated versions
animateToPosition, the single entry point for all snap animations.velocity = 0by default and are completely unaffected.Related