25
25
26
26
import com .facebook .infer .annotation .Assertions ;
27
27
import com .facebook .react .uimanager .MeasureSpecAssertions ;
28
- import com .facebook .react .uimanager .events . NativeGestureUtil ;
28
+ import com .facebook .react .uimanager .PixelUtil ;
29
29
import com .facebook .react .uimanager .ReactClippingViewGroup ;
30
30
import com .facebook .react .uimanager .ReactClippingViewGroupHelper ;
31
+ import com .facebook .react .uimanager .events .NativeGestureUtil ;
31
32
import com .facebook .react .views .view .ReactViewBackgroundDrawable ;
32
33
33
34
/**
@@ -43,6 +44,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements
43
44
private @ Nullable Rect mClippingRect ;
44
45
private boolean mDragging ;
45
46
private boolean mPagingEnabled = false ;
47
+ private double mSnapToInterval ;
46
48
private @ Nullable Runnable mPostTouchRunnable ;
47
49
private boolean mRemoveClippedSubviews ;
48
50
private boolean mScrollEnabled = true ;
@@ -92,6 +94,10 @@ public void setPagingEnabled(boolean pagingEnabled) {
92
94
mPagingEnabled = pagingEnabled ;
93
95
}
94
96
97
+ public void setSnapToInterval (double snapToInterval ) {
98
+ mSnapToInterval = snapToInterval ;
99
+ }
100
+
95
101
@ Override
96
102
protected void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
97
103
MeasureSpecAssertions .assertExplicitMeasureSpec (widthMeasureSpec , heightMeasureSpec );
@@ -233,6 +239,13 @@ private void disableFpsListener() {
233
239
}
234
240
}
235
241
242
+ private int getPageWidth () {
243
+ if (mSnapToInterval != 0 ) {
244
+ return (int ) (PixelUtil .toPixelFromDIP (mSnapToInterval ) + 0.5 );
245
+ }
246
+ return getWidth ();
247
+ }
248
+
236
249
private boolean isScrollPerfLoggingEnabled () {
237
250
return mFpsListener != null && mScrollPerfTag != null && !mScrollPerfTag .isEmpty ();
238
251
}
@@ -310,7 +323,7 @@ public void run() {
310
323
* scrolling.
311
324
*/
312
325
private void smoothScrollToPage (int velocity ) {
313
- int width = getWidth ();
326
+ int width = getPageWidth ();
314
327
int currentX = getScrollX ();
315
328
// TODO (t11123799) - Should we do anything beyond linear accounting of the velocity
316
329
int predictedX = currentX + velocity ;
0 commit comments