Skip to content

Commit

Permalink
Fix Android momentum scroll differences to iOS
Browse files Browse the repository at this point in the history
- Momentum scroll events should not be emitted when there's no momentum
- Momentum scroll should be interrupted by a drag, which should not emit
  an onMomentumScrollEnd event. Instead a new momentum scroll should
  begin once dragging ends.
  • Loading branch information
lnikkila committed Apr 21, 2019
1 parent f854b6a commit 9b2f1e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
ReactScrollViewHelper.emitScrollBeginDragEvent(this);
mDragging = true;
enableFpsListener();
// The user might be interrupting a fling/snap and we need to cancel any ongoing animations.
// Mirrors behaviour on iOS by starting a new momentum scroll event series after this drag.
if (mPostTouchRunnable != null) {
removeCallbacks(mPostTouchRunnable);
mPostTouchRunnable = null;
}
return true;
}
} catch (IllegalArgumentException e) {
Expand Down Expand Up @@ -445,6 +451,12 @@ private void handlePostTouchScrolling(int velocityX, int velocityY) {
return;
}

// Don't emit momentum events if there's not going to be a momentum scroll, mirrors iOS momentum
// scroll behaviour.
if (!mPagingEnabled && velocityX == 0 && velocityY == 0) {
return;
}

// Check if we are already handling this which may occur if this is called by both the touch up
// and a fling call
if (mPostTouchRunnable != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
ReactScrollViewHelper.emitScrollBeginDragEvent(this);
mDragging = true;
enableFpsListener();
// The user might be interrupting a fling/snap and we need to cancel any ongoing animations.
// Mirrors behaviour on iOS by starting a new momentum scroll event series after this drag.
if (mPostTouchRunnable != null) {
removeCallbacks(mPostTouchRunnable);
mPostTouchRunnable = null;
}
return true;
}
} catch (IllegalArgumentException e) {
Expand Down Expand Up @@ -412,6 +418,12 @@ private void handlePostTouchScrolling(int velocityX, int velocityY) {
return;
}

// Don't emit momentum events if there's not going to be a momentum scroll, mirrors iOS momentum
// scroll behaviour.
if (!mPagingEnabled && velocityX == 0 && velocityY == 0) {
return;
}

// Check if we are already handling this which may occur if this is called by both the touch up
// and a fling call
if (mPostTouchRunnable != null) {
Expand Down

0 comments on commit 9b2f1e9

Please sign in to comment.