From 1fa7150ce984fae57898de0564f176eb02389098 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 c10b6691a6a..8f3606e153b 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 @@ -595,7 +595,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 5222a552b10..e31a84e0576 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 @@ -556,7 +556,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