-
-
Notifications
You must be signed in to change notification settings - Fork 329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: onGestureEnd
-> endWithSpring
uses outdated data via useSharedValue
#574
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
"worklet"; | ||
const origin = translation.value; | ||
const velocity = scrollEndVelocity.value; | ||
const velocity = scrollEndVelocityValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, I'm explicitly leaving both the function parameter scrollEndVelocityValue
and this local const velocity
.
We could (should?) eliminate this line, though, and instead rename the function parameter to velocity
instead.
onGestureEnd
-> endWithSpring
uses outdated data via useSharedValue
When will it be released ? What is missing ? |
when it would be merged? |
What: the bug
When
endWithSpring
is called, it is using the previous values forscrollEndVelocity
andscrollEndTranslation
(rather than the values just set inonGestureEnd
). This seems to cause strange carousel behavior for the user: the function isn't using the values from the most recent pan.From the user's standpoint, the problem is very obvious (and potentially frustrating) when the user pans one direction, then reverses direction for their next pan. (Please see video demonstration below.)
Why
This is due to updates to shared values created via
useSharedValue()
updating asynchronously (see https://docs.swmansion.com/react-native-reanimated/docs/core/useSharedValue#remarks ).What: proposed fix
Rather than relying on the shared data variable between function calls, let's explicitly pass the values as arguments to
endWithSpring
.May resolve the following issues
Screengrab video recordings
buggy behavior on
4.0.0-alpha.10
(unpatched)Notice, panning the same direction works OK, but panning alternate direction fails.
Screen.Recording.2024-03-25.at.09.19.01.mov
improved behavior with patch
Screen.Recording.2024-03-25.at.09.24.18.mov