diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java index c5271853b4d..57a208c36ab 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java @@ -825,7 +825,6 @@ public class ReactHorizontalScrollView extends HorizontalScrollView new Runnable() { private boolean mSnappingToPage = false; - private boolean mRunning = true; private int mStableFrames = 0; @Override @@ -834,7 +833,8 @@ public class ReactHorizontalScrollView extends HorizontalScrollView // We are still scrolling. mActivelyScrolling = false; mStableFrames = 0; - mRunning = true; + ViewCompat.postOnAnimationDelayed( + ReactHorizontalScrollView.this, this, ReactScrollViewHelper.MOMENTUM_DELAY); } else { // There has not been a scroll update since the last time this Runnable executed. ReactScrollViewHelper.updateFabricScrollState(ReactHorizontalScrollView.this); @@ -847,31 +847,25 @@ public class ReactHorizontalScrollView extends HorizontalScrollView // fire before the first scroll event of an animated scroll/fling, and stop // immediately. mStableFrames++; - mRunning = (mStableFrames < 3); - if (mPagingEnabled && !mSnappingToPage) { - // Only if we have pagingEnabled and we have not snapped to the page do we - // need to continue checking for the scroll. And we cause that scroll by asking for - // it - mSnappingToPage = true; - flingAndSnap(0); - ViewCompat.postOnAnimationDelayed( - ReactHorizontalScrollView.this, this, ReactScrollViewHelper.MOMENTUM_DELAY); - } else { + if (mStableFrames >= 3) { + mPostTouchRunnable = null; if (mSendMomentumEvents) { ReactScrollViewHelper.emitScrollMomentumEndEvent(ReactHorizontalScrollView.this); } disableFpsListener(); + } else { + if (mPagingEnabled && !mSnappingToPage) { + // If we have pagingEnabled and we have not snapped to the page + // we need to cause that scroll by asking for it + mSnappingToPage = true; + flingAndSnap(0); + } + // The scrollview has not "stabilized" so we just post to check again a frame later + ViewCompat.postOnAnimationDelayed( + ReactHorizontalScrollView.this, this, ReactScrollViewHelper.MOMENTUM_DELAY); } } - - // We are still scrolling so we just post to check again a frame later - if (mRunning) { - ViewCompat.postOnAnimationDelayed( - ReactHorizontalScrollView.this, this, ReactScrollViewHelper.MOMENTUM_DELAY); - } else { - mPostTouchRunnable = null; - } } }; ViewCompat.postOnAnimationDelayed( diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java index 6bda8b8826b..86d9dafffe2 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java @@ -645,7 +645,6 @@ public class ReactScrollView extends ScrollView new Runnable() { private boolean mSnappingToPage = false; - private boolean mRunning = true; private int mStableFrames = 0; @Override @@ -654,7 +653,8 @@ public class ReactScrollView extends ScrollView // We are still scrolling. mActivelyScrolling = false; mStableFrames = 0; - mRunning = true; + ViewCompat.postOnAnimationDelayed( + ReactScrollView.this, this, ReactScrollViewHelper.MOMENTUM_DELAY); } else { // There has not been a scroll update since the last time this Runnable executed. ReactScrollViewHelper.updateFabricScrollState(ReactScrollView.this); @@ -667,31 +667,25 @@ public class ReactScrollView extends ScrollView // fire before the first scroll event of an animated scroll/fling, and stop // immediately. mStableFrames++; - mRunning = (mStableFrames < 3); - if (mPagingEnabled && !mSnappingToPage) { - // Only if we have pagingEnabled and we have not snapped to the page do we - // need to continue checking for the scroll. And we cause that scroll by asking for - // it - mSnappingToPage = true; - flingAndSnap(0); - ViewCompat.postOnAnimationDelayed( - ReactScrollView.this, this, ReactScrollViewHelper.MOMENTUM_DELAY); - } else { + if (mStableFrames >= 3) { + mPostTouchRunnable = null; if (mSendMomentumEvents) { ReactScrollViewHelper.emitScrollMomentumEndEvent(ReactScrollView.this); } disableFpsListener(); + } else { + if (mPagingEnabled && !mSnappingToPage) { + // If we have pagingEnabled and we have not snapped to the page + // we need to cause that scroll by asking for it + mSnappingToPage = true; + flingAndSnap(0); + } + // The scrollview has not "stabilized" so we just post to check again a frame later + ViewCompat.postOnAnimationDelayed( + ReactScrollView.this, this, ReactScrollViewHelper.MOMENTUM_DELAY); } } - - // We are still scrolling so we just post to check again a frame later - if (mRunning) { - ViewCompat.postOnAnimationDelayed( - ReactScrollView.this, this, ReactScrollViewHelper.MOMENTUM_DELAY); - } else { - mPostTouchRunnable = null; - } } }; ViewCompat.postOnAnimationDelayed(