fix: bad initial scrollInit value causes auto-scroll when drag begins #533
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.
Thank you for your work on this project!
Problem:
Reproduce:
This is especially noticeable if you increase the auto-scroll speed, as it can displace the dragging item by multiple slots before you move your finger.
Technical problem:
useAnimatedReaction
hook inanimatedValueContext.tsx
, thescrollInit
value updates in the render AFTERactiveIndexAnim
is set. Therefore,autoScrollDistance
triggers, but with an initially-inaccuratescrollInit
. On the next render,scrollInit
is accurate, but it's too late because the auto-scroll animation already caused a jumpSolution:
scrollInit
to -1, resetting the value when the active index resets. While it's -1 (uninitialized), forceautoScrollDistance
to return zero.Before:
https://github.com/computerjazz/react-native-draggable-flatlist/assets/66435161/c132b0c2-9165-4081-9525-287de7dd6cfa
After:
Screen.Recording.2024-05-05.at.7.12.33.PM.mov