From 6eeff75849c9b8bf91592c1b7906b4dab8fba518 Mon Sep 17 00:00:00 2001 From: Oleg Lokhvitsky Date: Thu, 11 Oct 2018 09:57:11 -0700 Subject: [PATCH] Android ScrollView fix for snapToInterval not snapping to end Summary: The end-of-scrollable-range offset was not clipped before the nearestOffset calculation causing the ScrollView to not snap to the end of the view when the width of the ScrollView was not an exact multiple of snapToInterval. Addresses https://github.com/facebook/react-native/issues/21116#issuecomment-427944838 Reviewed By: yungsters Differential Revision: D10248545 fbshipit-source-id: 2bdc94ea0a9d9f063769f2c5da4c33d4872b1db2 --- .../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 c46a1ea24..bf6c3bd51 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 @@ -608,7 +608,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements double interval = (double) getSnapInterval(); double ratio = (double) targetOffset / interval; smallerOffset = (int) (Math.floor(ratio) * interval); - largerOffset = (int) (Math.ceil(ratio) * interval); + largerOffset = Math.min((int) (Math.ceil(ratio) * interval), maximumOffset); } // Calculate the nearest offset 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 36d02457a..f10bd47eb 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 @@ -569,7 +569,7 @@ public class ReactScrollView extends ScrollView implements ReactClippingViewGrou double interval = (double) getSnapInterval(); double ratio = (double) targetOffset / interval; smallerOffset = (int) (Math.floor(ratio) * interval); - largerOffset = (int) (Math.ceil(ratio) * interval); + largerOffset = Math.min((int) (Math.ceil(ratio) * interval), maximumOffset); } // Calculate the nearest offset