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);
int action = ev.getAction() & MotionEvent.ACTION_MASK;
if (action == MotionEvent.ACTION_UP && mDragging) {
float velocityX = mVelocityHelper.getXVelocity();
float velocityY = mVelocityHelper.getYVelocity();
ReactScrollViewHelper.emitScrollEndDragEvent(
this,
mVelocityHelper.getXVelocity(),
mVelocityHelper.getYVelocity());
velocityX,
velocityY);
mDragging = false;
// 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
handlePostTouchScrolling();
handlePostTouchScrolling(Math.round(velocityX), Math.round(velocityY));
}
return super.onTouchEvent(ev);
@ -178,7 +180,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements
} else {
super.fling(velocityX);
}
handlePostTouchScrolling();
handlePostTouchScrolling(velocityX, 0);
}
@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.
*/
@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 (!mSendMomentumEvents && !mPagingEnabled && !isScrollPerfLoggingEnabled()) {
return;
@ -283,7 +285,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView implements
}
if (mSendMomentumEvents) {
ReactScrollViewHelper.emitScrollMomentumBeginEvent(this);
ReactScrollViewHelper.emitScrollMomentumBeginEvent(this, velocityX, velocityY);
}
mActivelyScrolling = false;

View File

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

View File

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