Send scroll velocity data to Javascript on momentum scroll events.

Reviewed By: sahrens

Differential Revision: D6643379

fbshipit-source-id: 70550274975ed7c2b43a3d668422102d0c115ba7
This commit is contained in:
Wesley Walser 2018-01-05 10:34:47 -08:00 committed by Facebook Github Bot
parent 33d710e8c5
commit c49d249fd7
3 changed files with 14 additions and 9 deletions

View File

@ -158,14 +158,16 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements
mVelocityHelper.calculateVelocity(ev); mVelocityHelper.calculateVelocity(ev);
int action = ev.getAction() & MotionEvent.ACTION_MASK; int action = ev.getAction() & MotionEvent.ACTION_MASK;
if (action == MotionEvent.ACTION_UP && mDragging) { if (action == MotionEvent.ACTION_UP && mDragging) {
float velocityX = mVelocityHelper.getXVelocity();
float velocityY = mVelocityHelper.getYVelocity();
ReactScrollViewHelper.emitScrollEndDragEvent( ReactScrollViewHelper.emitScrollEndDragEvent(
this, this,
mVelocityHelper.getXVelocity(), velocityX,
mVelocityHelper.getYVelocity()); velocityY);
mDragging = false; mDragging = false;
// After the touch finishes, we may need to do some scrolling afterwards either as a result // After the touch finishes, we may need to do some scrolling afterwards either as a result
// of a fling or because we need to page align the content // of a fling or because we need to page align the content
handlePostTouchScrolling(); handlePostTouchScrolling(Math.round(velocityX), Math.round(velocityY));
} }
return super.onTouchEvent(ev); return super.onTouchEvent(ev);
@ -178,7 +180,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements
} else { } else {
super.fling(velocityX); super.fling(velocityX);
} }
handlePostTouchScrolling(); handlePostTouchScrolling(velocityX, 0);
} }
@Override @Override
@ -270,7 +272,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements
* runnable that checks if we scrolled in the last frame and if so assumes we are still scrolling. * runnable that checks if we scrolled in the last frame and if so assumes we are still scrolling.
*/ */
@TargetApi(16) @TargetApi(16)
private void handlePostTouchScrolling() { private void handlePostTouchScrolling(int velocityX, int velocityY) {
// If we aren't going to do anything (send events or snap to page), we can early out. // If we aren't going to do anything (send events or snap to page), we can early out.
if (!mSendMomentumEvents && !mPagingEnabled && !isScrollPerfLoggingEnabled()) { if (!mSendMomentumEvents && !mPagingEnabled && !isScrollPerfLoggingEnabled()) {
return; return;
@ -283,7 +285,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements
} }
if (mSendMomentumEvents) { if (mSendMomentumEvents) {
ReactScrollViewHelper.emitScrollMomentumBeginEvent(this); ReactScrollViewHelper.emitScrollMomentumBeginEvent(this, velocityX, velocityY);
} }
mActivelyScrolling = false; mActivelyScrolling = false;

View File

@ -279,7 +279,7 @@ public class ReactScrollView extends ScrollView implements ReactClippingViewGrou
if (mSendMomentumEvents || isScrollPerfLoggingEnabled()) { if (mSendMomentumEvents || isScrollPerfLoggingEnabled()) {
mFlinging = true; mFlinging = true;
enableFpsListener(); enableFpsListener();
ReactScrollViewHelper.emitScrollMomentumBeginEvent(this); ReactScrollViewHelper.emitScrollMomentumBeginEvent(this, 0, velocityY);
Runnable r = new Runnable() { Runnable r = new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -44,8 +44,11 @@ public class ReactScrollViewHelper {
emitScrollEvent(scrollView, ScrollEventType.END_DRAG, xVelocity, yVelocity); emitScrollEvent(scrollView, ScrollEventType.END_DRAG, xVelocity, yVelocity);
} }
public static void emitScrollMomentumBeginEvent(ViewGroup scrollView) { public static void emitScrollMomentumBeginEvent(
emitScrollEvent(scrollView, ScrollEventType.MOMENTUM_BEGIN); ViewGroup scrollView,
int xVelocity,
int yVelocity) {
emitScrollEvent(scrollView, ScrollEventType.MOMENTUM_BEGIN, xVelocity, yVelocity);
} }
public static void emitScrollMomentumEndEvent(ViewGroup scrollView) { public static void emitScrollMomentumEndEvent(ViewGroup scrollView) {