From 61e1b6f86cf98d8a74eeb9353143fe0c624fe6e6 Mon Sep 17 00:00:00 2001 From: Xin Chen Date: Wed, 27 Oct 2021 13:58:03 -0700 Subject: [PATCH] Fix #flingAndSnap to check all the scroll item for offset range Summary: When calculating the offset range, we assume the first item is always at offset zero position and skipped that (as the smallerOffset is zero). However, this may not be the case in some situations. This diff changes the range measuring loop to always start from the first item. Changelog: [Android][Fixed] - Do NOT skip the first child view in the scroll view group when measuring the lower and upper bounds for snapping. Reviewed By: mdvacca Differential Revision: D31887086 fbshipit-source-id: af7221a621b2719d057afa6b64aa91c94ac01295 --- .../facebook/react/views/scroll/ReactHorizontalScrollView.java | 2 +- .../java/com/facebook/react/views/scroll/ReactScrollView.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java index 470c7d0f9bff70..a92a848c688b0d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java @@ -983,7 +983,7 @@ private void flingAndSnap(int velocityX) { maximumOffset); } else { ViewGroup contentView = (ViewGroup) getContentView(); - for (int i = 1; i < contentView.getChildCount(); i++) { + for (int i = 0; i < contentView.getChildCount(); i++) { View item = contentView.getChildAt(i); int itemStartOffset = getItemStartOffset(mSnapToAlignment, item.getLeft(), item.getWidth(), width); diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java index 3b2265aa186e0d..2abf2923a3e0a5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java @@ -766,7 +766,7 @@ private void flingAndSnap(int velocityY) { maximumOffset); } else { ViewGroup contentView = (ViewGroup) getContentView(); - for (int i = 1; i < contentView.getChildCount(); i++) { + for (int i = 0; i < contentView.getChildCount(); i++) { View item = contentView.getChildAt(i); int itemStartOffset; switch (mSnapToAlignment) {