-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: stop ongoing momentum when calling scrollTo (ANDROID) #5286
base: main
Are you sure you want to change the base?
Conversation
@Bowlerr I noticed this solution is Android only, I've got an iOS issue that might be separate, but just wanted to confirm that you've only seen this on Android? |
@henrymoulton Yeah I've only seen this issue on Android. No issue on iOS to our knowledge. |
Is it necessary for FlatList too? Trying to pin down the issue I'm having with multiple calls to |
@henrymoulton in my video example, I'm using two flatlists so I'm assuming anything on Android that uses scrollTo. Haven't done extensive testing myself. |
Hey @Bowlerr, thanks for submitting this PR. Prior to merging, we would like to test out the PR. Could you please share the source code of the example? |
So if you look at my example code, it may help you solve your issue @henrymoulton |
@tomekzaw Added some Example code :) let me know if there is any issues |
@Bowlerr Thanks for the source code. I was able to reproduce the issue on the example you have provided. When I scroll one ScrollView and it gains momentum and then scroll the second scroll view, the first ScrollView is not affected until the momentum ends. The code in this PR indeed seems to fix this problem. I appreciate your effort but at this point I'm not 100% convinced if this is the best possible solution. In particular:
I will try to get answers to these questions on my own so we can polish this PR but obviously your help would be appreciated. edit: actually I think this problem should be fixed by facebook/react-native#39529 (for horizontal scroll view) |
@tomekzaw Thanks for the feedback! I introduced two new methods,
Please let me know what you think and if there are any further adjustments needed. |
Hey @Bowlerr I'm thinking of patch-packaging facebook/react-native#39529 into my codebase for now |
Summary
This PR addresses an issue where the scroll momentum in
ReactScrollView
andReactHorizontalScrollView
was not being interrupted when a new scroll action was initiated usingScrollTo
. This often resulted in janky user experiences, especially when quick consecutive scrolls were performed.By introducing a small scroll action before the actual scroll, we can effectively stop any ongoing momentum, ensuring smoother transitions between scroll actions.
Test plan
To test this change:
Clone the repository and check out the branch with the changes.
Navigate to a screen in your React Native app that uses either ReactScrollView or ReactHorizontalScrollView.
Perform a fling action to initiate scroll momentum.
Before the momentum stops, try to programmatically scroll the view using the scrollTo method.
Observe that the previous momentum is stopped and the view scrolls to the desired position smoothly.
Expected behavior:
The scroll view should immediately interrupt its current momentum and smoothly scroll to the specified position.
Before:
Before YT link
After:
After YT link
Example Source Code: