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
This commit is contained in:
Oleg Lokhvitsky
2018-10-11 09:57:11 -07:00
committed by Facebook Github Bot
parent 83da74b556
commit 6eeff75849
2 changed files with 2 additions and 2 deletions

View File

@@ -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

View File

@@ -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