Skip to content
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: bad initial scrollInit value causes auto-scroll when drag begins #533

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

justinjaeger
Copy link

@justinjaeger justinjaeger commented May 5, 2024

Thank you for your work on this project!

Problem:

  • lists auto-scroll unnecessarily when drag begins when scrollY is not at 0

Reproduce:

  • scrolled down the draggable list any amount
  • trigger the "drag"
  • component auto-scrolls unnecessarily, then stops

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:

  • in the useAnimatedReaction hook in animatedValueContext.tsx, the scrollInit value updates in the render AFTER activeIndexAnim is set. Therefore, autoScrollDistance triggers, but with an initially-inaccurate scrollInit. On the next render, scrollInit is accurate, but it's too late because the auto-scroll animation already caused a jump

Solution:

  • initialize scrollInit to -1, resetting the value when the active index resets. While it's -1 (uninitialized), force autoScrollDistance 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant