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 69da5b3af197a4..ae0a51274e7113 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 @@ -20,6 +20,7 @@ import android.graphics.Rect; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +import android.os.Build; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; @@ -480,18 +481,7 @@ public boolean getChildVisibleRect(View child, Rect r, android.graphics.Point of @Override public void fling(int velocityY) { - // Workaround. - // On Android P if a ScrollView is inverted, we will get a wrong sign for - // velocityY (see https://issuetracker.google.com/issues/112385925). - // At the same time, mOnScrollDispatchHelper tracks the correct velocity direction. - // - // Hence, we can use the absolute value from whatever the OS gives - // us and use the sign of what mOnScrollDispatchHelper has tracked. - float signum = Math.signum(mOnScrollDispatchHelper.getYFlingVelocity()); - if (signum == 0) { - signum = Math.signum(velocityY); - } - final int correctedVelocityY = (int) (Math.abs(velocityY) * signum); + final int correctedVelocityY = correctFlingVelocityY(velocityY); if (mPagingEnabled) { flingAndSnap(correctedVelocityY); @@ -530,6 +520,25 @@ public void fling(int velocityY) { handlePostTouchScrolling(0, correctedVelocityY); } + private int correctFlingVelocityY(int velocityY) { + if (Build.VERSION.SDK_INT != Build.VERSION_CODES.P) { + return velocityY; + } + + // Workaround. + // On Android P if a ScrollView is inverted, we will get a wrong sign for + // velocityY (see https://issuetracker.google.com/issues/112385925). + // At the same time, mOnScrollDispatchHelper tracks the correct velocity direction. + // + // Hence, we can use the absolute value from whatever the OS gives + // us and use the sign of what mOnScrollDispatchHelper has tracked. + float signum = Math.signum(mOnScrollDispatchHelper.getYFlingVelocity()); + if (signum == 0) { + signum = Math.signum(velocityY); + } + return (int) (Math.abs(velocityY) * signum); + } + private void enableFpsListener() { if (isScrollPerfLoggingEnabled()) { Assertions.assertNotNull(mFpsListener);