Permalink
Browse files

Send scroll velocity data to Javascript on momentum scroll events.

Reviewed By: sahrens

Differential Revision: D6643379

fbshipit-source-id: 70550274975ed7c2b43a3d668422102d0c115ba7
  • Loading branch information...
wwalser authored and facebook-github-bot committed Jan 5, 2018
1 parent 33d710e commit c49d249fd7c274f02e6018892992bcd273d6a465
@@ -158,14 +158,16 @@ public boolean onTouchEvent(MotionEvent ev) {
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 void fling(int velocityX) {
} else {
super.fling(velocityX);
}
handlePostTouchScrolling();
handlePostTouchScrolling(velocityX, 0);
}
@Override
@@ -270,7 +272,7 @@ public void draw(Canvas canvas) {
* 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 @@ private void handlePostTouchScrolling() {
}
if (mSendMomentumEvents) {
ReactScrollViewHelper.emitScrollMomentumBeginEvent(this);
ReactScrollViewHelper.emitScrollMomentumBeginEvent(this, velocityX, velocityY);
}
mActivelyScrolling = false;
@@ -279,7 +279,7 @@ public void fling(int velocityY) {
if (mSendMomentumEvents || isScrollPerfLoggingEnabled()) {
mFlinging = true;
enableFpsListener();
ReactScrollViewHelper.emitScrollMomentumBeginEvent(this);
ReactScrollViewHelper.emitScrollMomentumBeginEvent(this, 0, velocityY);
Runnable r = new Runnable() {
@Override
public void run() {
@@ -44,8 +44,11 @@ public static void emitScrollEndDragEvent(
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) {

0 comments on commit c49d249

Please sign in to comment.