From 323add49124225491eb64ff6c25e83d103a20de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leo=20Nikkil=C3=A4?= Date: Fri, 20 Jul 2018 01:33:47 +0300 Subject: [PATCH] Fix Android onMomentumScrollEnd when interrupted Interrupting a momentum scroll by dragging will incorrectly fire two `onMomentumScrollEnd` events, both of which happen too early. This can be fixed by stopping the fling when the user starts dragging again and checking whether the fling is still going on in the runnable that eventually detects when a fling has ended. Fixes #18568. --- .../com/facebook/react/views/scroll/ReactScrollView.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java index 57b401cd6fbf5c..d89841d080145e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java @@ -194,6 +194,8 @@ public boolean onInterceptTouchEvent(MotionEvent ev) { NativeGestureUtil.notifyNativeGestureStarted(this, ev); ReactScrollViewHelper.emitScrollBeginDragEvent(this); mDragging = true; + mFlinging = false; + mDoneFlinging = false; enableFpsListener(); return true; } @@ -300,6 +302,11 @@ public void fling(int velocityY) { Runnable r = new Runnable() { @Override public void run() { + // It's possible the fling was interrupted by the user. + if (!mFlinging) { + return; + } + if (mDoneFlinging) { mFlinging = false; disableFpsListener();