Skip to content

Commit 396d444

Browse files
NickGerlemanhuntie
authored andcommitted
Fix Android HorizontalScrollView fling when content length less than ScrollView length (#43563)
Summary: Pull Request resolved: #43563 Fixes #42874 ## Sumary D9405703 added some custom logic for Flings, to support FlatList scenarios where content is being added on the fly, during Fling animation. This works by allowing start Fling to not have bounds, then correcting/cancelling Fling when overscroll happens over a bound that would normally be allowed. This has some math to try to determine max content length, and will clamp to this when scrolling over it. This logic is incorrect when content length is less than scrollview length, and we end up snapping to a negative offset. This change adds clamping, so that we don't snap to negative position in horizontal scroll view. This clamping was already indirectly present on vertical scroll view. https://www.internalfb.com/code/fbsource/[b43cdf9b2fec71f5341ec8ff2d47e28a066f052e]/xplat/js/react-native-github/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java?lines=609 ## Test Plan Above issue no longer reproes. Flinging while content is being added to horizontal FlatList still works correctly. Changelog: [Android][Fixed] - Fix Android HorizontalScrollView fling when content length less than ScrollView length Reviewed By: javache Differential Revision: D55108818 fbshipit-source-id: 7cf0065f9f92832cc2606d1c7534fc150407b9c9
1 parent 20bcf57 commit 396d444

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolea
807807
// more information.
808808

809809
if (!mScroller.isFinished() && mScroller.getCurrX() != mScroller.getFinalX()) {
810-
int scrollRange = computeHorizontalScrollRange() - getWidth();
810+
int scrollRange = Math.max(computeHorizontalScrollRange() - getWidth(), 0);
811811
if (scrollX >= scrollRange) {
812812
mScroller.abortAnimation();
813813
scrollX = scrollRange;

0 commit comments

Comments
 (0)