diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java index 51066cc02b9279..5d5d67f3ff4173 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java @@ -432,13 +432,7 @@ protected void onScrollChanged(int x, int y, int oldX, int oldY) { updateClippingRect(); } - // Race an UpdateState with every onScroll. This makes it more likely that, in Fabric, - // when JS processes the scroll event, the C++ ShadowNode representation will have a - // "more correct" scroll position. It will frequently be /incorrect/ but this decreases - // the error as much as possible. - ReactScrollViewHelper.updateStateOnScroll(this); - - ReactScrollViewHelper.emitScrollEvent( + ReactScrollViewHelper.updateStateOnScrollChanged( this, mOnScrollDispatchHelper.getXFlingVelocity(), mOnScrollDispatchHelper.getYFlingVelocity()); @@ -521,7 +515,7 @@ public boolean onTouchEvent(MotionEvent ev) { mVelocityHelper.calculateVelocity(ev); int action = ev.getAction() & MotionEvent.ACTION_MASK; if (action == MotionEvent.ACTION_UP && mDragging) { - ReactScrollViewHelper.updateStateOnScroll(this); + ReactScrollViewHelper.updateFabricScrollState(this); float velocityX = mVelocityHelper.getXVelocity(); float velocityY = mVelocityHelper.getYVelocity(); @@ -769,7 +763,7 @@ public void run() { mRunning = true; } else { // There has not been a scroll update since the last time this Runnable executed. - ReactScrollViewHelper.updateStateOnScroll(ReactHorizontalScrollView.this); + ReactScrollViewHelper.updateFabricScrollState(ReactHorizontalScrollView.this); // We keep checking for updates until the ScrollView has "stabilized" and hasn't // scrolled for N consecutive frames. This number is arbitrary: big enough to catch @@ -1178,7 +1172,7 @@ public void scrollTo(int x, int y) { // to the last item in the list, but that item cannot be move to the start position of the view. final int actualX = getScrollX(); final int actualY = getScrollY(); - ReactScrollViewHelper.updateStateOnScroll(this, actualX, actualY); + ReactScrollViewHelper.updateFabricScrollState(this, actualX, actualY); setPendingContentOffsets(actualX, actualY); } 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 cf3de29afa4cfc..044103c7cdbeca 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 @@ -312,13 +312,7 @@ protected void onScrollChanged(int x, int y, int oldX, int oldY) { updateClippingRect(); } - // Race an UpdateState with every onScroll. This makes it more likely that, in Fabric, - // when JS processes the scroll event, the C++ ShadowNode representation will have a - // "more correct" scroll position. It will frequently be /incorrect/ but this decreases - // the error as much as possible. - ReactScrollViewHelper.updateStateOnScroll(this); - - ReactScrollViewHelper.emitScrollEvent( + ReactScrollViewHelper.updateStateOnScrollChanged( this, mOnScrollDispatchHelper.getXFlingVelocity(), mOnScrollDispatchHelper.getYFlingVelocity()); @@ -359,7 +353,7 @@ public boolean onTouchEvent(MotionEvent ev) { mVelocityHelper.calculateVelocity(ev); int action = ev.getAction() & MotionEvent.ACTION_MASK; if (action == MotionEvent.ACTION_UP && mDragging) { - ReactScrollViewHelper.updateStateOnScroll(this); + ReactScrollViewHelper.updateFabricScrollState(this); float velocityX = mVelocityHelper.getXVelocity(); float velocityY = mVelocityHelper.getYVelocity(); @@ -558,7 +552,7 @@ public void run() { mRunning = true; } else { // There has not been a scroll update since the last time this Runnable executed. - ReactScrollViewHelper.updateStateOnScroll(ReactScrollView.this); + ReactScrollViewHelper.updateFabricScrollState(ReactScrollView.this); // We keep checking for updates until the ScrollView has "stabilized" and hasn't // scrolled for N consecutive frames. This number is arbitrary: big enough to catch @@ -953,7 +947,7 @@ public void scrollTo(int x, int y) { // to the last item in the list, but that item cannot be move to the start position of the view. final int actualX = getScrollX(); final int actualY = getScrollY(); - ReactScrollViewHelper.updateStateOnScroll(this, actualX, actualY); + ReactScrollViewHelper.updateFabricScrollState(this, actualX, actualY); setPendingContentOffsets(actualX, actualY); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java index 62f3ff94090dc7..03238555f2b53c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java @@ -342,7 +342,7 @@ void smoothScrollTo(final T scrollView, final int x, final int y) { scrollView.startFlingAnimator(scrollY, y); } - updateStateOnScroll(scrollView, x, y); + updateFabricScrollState(scrollView, x, y); } /** Get current (x, y) position or position after current animation finishes, if any. */ @@ -386,8 +386,8 @@ Point getPostAnimationScroll(final T scrollView, final boolean isPositiveVelocit T extends ViewGroup & FabricViewStateManager.HasFabricViewStateManager & HasScrollState & HasFlingAnimator> - boolean updateStateOnScroll(final T scrollView) { - return updateStateOnScroll(scrollView, scrollView.getScrollX(), scrollView.getScrollY()); + boolean updateFabricScrollState(final T scrollView) { + return updateFabricScrollState(scrollView, scrollView.getScrollX(), scrollView.getScrollY()); } /** @@ -397,11 +397,11 @@ boolean updateStateOnScroll(final T scrollView) { T extends ViewGroup & FabricViewStateManager.HasFabricViewStateManager & HasScrollState & HasFlingAnimator> - boolean updateStateOnScroll(final T scrollView, final int scrollX, final int scrollY) { + boolean updateFabricScrollState(final T scrollView, final int scrollX, final int scrollY) { if (DEBUG_MODE) { FLog.i( TAG, - "updateStateOnScroll[%d] scrollX %d scrollY %d", + "updateFabricScrollState[%d] scrollX %d scrollY %d", scrollView.getId(), scrollX, scrollY); @@ -448,7 +448,7 @@ void forceUpdateState(final T scrollView) { if (DEBUG_MODE) { FLog.i( TAG, - "updateStateOnScroll[%d] scrollX %d scrollY %d fabricScrollX", + "updateFabricScrollState[%d] scrollX %d scrollY %d fabricScrollX", scrollView.getId(), scrollX, scrollY, @@ -471,6 +471,20 @@ public WritableMap getStateUpdate() { }); } + public static < + T extends + ViewGroup & FabricViewStateManager.HasFabricViewStateManager & HasScrollState + & HasFlingAnimator> + void updateStateOnScrollChanged( + final T scrollView, final float xVelocity, final float yVelocity) { + // Race an UpdateState with every onScroll. This makes it more likely that, in Fabric, + // when JS processes the scroll event, the C++ ShadowNode representation will have a + // "more correct" scroll position. It will frequently be /incorrect/ but this decreases + // the error as much as possible. + updateFabricScrollState(scrollView); + emitScrollEvent(scrollView, xVelocity, yVelocity); + } + public static < T extends ViewGroup & FabricViewStateManager.HasFabricViewStateManager & HasScrollState @@ -491,7 +505,7 @@ public void onAnimationStart(Animator animator) { @Override public void onAnimationEnd(Animator animator) { scrollView.getReactScrollViewScrollState().setIsFinished(true); - ReactScrollViewHelper.updateStateOnScroll(scrollView); + updateFabricScrollState(scrollView); } @Override