-
Notifications
You must be signed in to change notification settings - Fork 24.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 maintainVisibleContentPosition on Android during momentum scroll #43425
Conversation
Base commit: 6c50418 |
...ve/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java
Show resolved
Hide resolved
@NickGerleman I updated it to use the same logic from HorizontalScrollView (and added it to ScrollView). |
// If we have any pending custon flings (e.g. from aninmated `scrollTo`, or flinging to a snap | ||
// point), finish them, commiting the final `scrollX`. | ||
// TODO: Can we be more graceful (like OverScroller flings)? | ||
if (getFlingAnimator().isRunning()) { | ||
getFlingAnimator().end(); | ||
} |
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.
Is this piece still relevant? I.e. if adjustment happens during programmatically triggered fling?
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.
I think it would be pretty rare cases, but I added the extra logic just in case.
There I used cancel instead of end since I do not want to commit the last scroll position of the animation. I think it is better to cancel the scroll still than to have content jumps because of the animation being wrong.
@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@NickGerleman merged this pull request in a9e6759. |
Wow that was so quick compared to how long it took for the original issue to be fixed! |
Summary:
When using maintainVisibleContentPosition (mvcp) on Android it doesn't work properly when items are added during a momentum scroll. This happens because the android scrollview momentum scroll animation overrides the scroll position that the mvcp implementation sets here.
To fix this we need to cancel the momentum scroll animation, update the scroll position then restart the scroll animation with the previous animation remaining momentum.
Changelog:
[ANDROID] [FIXED] - Fix maintainVisibleContentPosition during momentum scroll
Test Plan:
Tested in RNTester on Android with both vertical and horizontal scrollviews using the following code:
Before:
Screen.Recording.2024-03-11.at.23.03.27.mov
After:
Screen.Recording.2024-03-11.at.22.42.16.mov