Skip to content

Commit df3cd99

Browse files
committed
Fix ScrollView with pagingEnabled when using ThumbStick
1 parent 7c9b862 commit df3cd99

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,38 @@ public boolean dispatchGenericMotionEvent(MotionEvent ev) {
718718
return false;
719719
}
720720

721+
// Handle ACTION_SCROLL events (mouse wheel, trackpad, joystick)
722+
if (ev.getActionMasked() == MotionEvent.ACTION_SCROLL) {
723+
float hScroll = ev.getAxisValue(MotionEvent.AXIS_HSCROLL);
724+
if (hScroll != 0) {
725+
// Perform the scroll
726+
boolean result = super.dispatchGenericMotionEvent(ev);
727+
// Schedule snap alignment to run after scrolling stops
728+
if (result
729+
&& (mPagingEnabled
730+
|| mSnapInterval != 0
731+
|| mSnapOffsets != null
732+
|| mSnapToAlignment != SNAP_ALIGNMENT_DISABLED)) {
733+
// Cancel any pending runnable and reschedule
734+
if (mPostTouchRunnable != null) {
735+
removeCallbacks(mPostTouchRunnable);
736+
}
737+
mPostTouchRunnable =
738+
new Runnable() {
739+
@Override
740+
public void run() {
741+
mPostTouchRunnable = null;
742+
// Trigger snap alignment now that scrolling has stopped
743+
handlePostTouchScrolling(0, 0);
744+
}
745+
};
746+
ViewCompat.postOnAnimationDelayed(
747+
this, mPostTouchRunnable, ReactScrollViewHelper.MOMENTUM_DELAY);
748+
}
749+
return result;
750+
}
751+
}
752+
721753
return super.dispatchGenericMotionEvent(ev);
722754
}
723755

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,38 @@ public boolean dispatchGenericMotionEvent(MotionEvent ev) {
557557
return false;
558558
}
559559

560+
// Handle ACTION_SCROLL events (mouse wheel, trackpad, joystick)
561+
if (ev.getActionMasked() == MotionEvent.ACTION_SCROLL) {
562+
float vScroll = ev.getAxisValue(MotionEvent.AXIS_VSCROLL);
563+
if (vScroll != 0) {
564+
// Perform the scroll
565+
boolean result = super.dispatchGenericMotionEvent(ev);
566+
// Schedule snap alignment to run after scrolling stops
567+
if (result
568+
&& (mPagingEnabled
569+
|| mSnapInterval != 0
570+
|| mSnapOffsets != null
571+
|| mSnapToAlignment != SNAP_ALIGNMENT_DISABLED)) {
572+
// Cancel any pending post-touch runnable and reschedule
573+
if (mPostTouchRunnable != null) {
574+
removeCallbacks(mPostTouchRunnable);
575+
}
576+
mPostTouchRunnable =
577+
new Runnable() {
578+
@Override
579+
public void run() {
580+
mPostTouchRunnable = null;
581+
// Trigger snap alignment now that scrolling has stopped
582+
handlePostTouchScrolling(0, 0);
583+
}
584+
};
585+
ViewCompat.postOnAnimationDelayed(
586+
this, mPostTouchRunnable, ReactScrollViewHelper.MOMENTUM_DELAY);
587+
}
588+
return result;
589+
}
590+
}
591+
560592
return super.dispatchGenericMotionEvent(ev);
561593
}
562594

0 commit comments

Comments
 (0)