From fcec81536859211e666c14be5c437819fdccf9e6 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Wed, 4 Mar 2020 14:15:40 -0800 Subject: [PATCH] Fix what updateState in ScrollView when called from reactSmoothScrollTo Summary: Changelog: [Internal] # Problem Fabric didn't know about content offset, even though `reactSmoothScrollTo` calls `updateStateOnScroll`, the value of content offset is {0, 0}. # Fix Call `updateStateOnScroll` from `reactSmoothScrollTo` with where the scroll view is going to be rather than where it is. Reviewed By: JoshuaGross, mdvacca Differential Revision: D20248959 fbshipit-source-id: b1da645576dd5e8dce29e7e1d90ab232e0df9fd5 --- .../react/views/scroll/ReactScrollView.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 6d4b0e957b5..6bd0be83620 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 @@ -299,7 +299,7 @@ public class ReactScrollView extends ScrollView mVelocityHelper.calculateVelocity(ev); int action = ev.getAction() & MotionEvent.ACTION_MASK; if (action == MotionEvent.ACTION_UP && mDragging) { - updateStateOnScroll(); + updateStateOnScroll(getScrollX(), getScrollY()); float velocityX = mVelocityHelper.getXVelocity(); float velocityY = mVelocityHelper.getYVelocity(); @@ -502,7 +502,7 @@ public class ReactScrollView extends ScrollView ViewCompat.postOnAnimationDelayed( ReactScrollView.this, this, ReactScrollViewHelper.MOMENTUM_DELAY); } else { - updateStateOnScroll(); + updateStateOnScroll(getScrollX(), getScrollY()); if (mPagingEnabled && !mSnappingToPage) { // Only if we have pagingEnabled and we have not snapped to the page do we @@ -776,7 +776,7 @@ public class ReactScrollView extends ScrollView */ public void reactSmoothScrollTo(int x, int y) { smoothScrollTo(x, y); - updateStateOnScroll(); + updateStateOnScroll(x, y); } /** @@ -787,7 +787,7 @@ public class ReactScrollView extends ScrollView */ public void reactScrollTo(int x, int y) { scrollTo(x, y); - updateStateOnScroll(); + updateStateOnScroll(x, y); } /** @@ -849,14 +849,14 @@ public class ReactScrollView extends ScrollView /** * Called on any stabilized onScroll change to propagate content offset value to a Shadow Node. */ - private void updateStateOnScroll() { + private void updateStateOnScroll(int scrollX, int scrollY) { if (mStateWrapper == null) { return; } WritableMap map = new WritableNativeMap(); - map.putDouble(CONTENT_OFFSET_LEFT, PixelUtil.toDIPFromPixel(getScrollX())); - map.putDouble(CONTENT_OFFSET_TOP, PixelUtil.toDIPFromPixel(getScrollY())); + map.putDouble(CONTENT_OFFSET_LEFT, PixelUtil.toDIPFromPixel(scrollX)); + map.putDouble(CONTENT_OFFSET_TOP, PixelUtil.toDIPFromPixel(scrollY)); mStateWrapper.updateState(map); }