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 e9b99417a43826..8624f648dd0b4d 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 @@ -254,8 +254,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { // Call with the present values in order to re-layout if necessary - // If a "pending" value has been set, we restore that value. - // That value gets cleared by reactScrollTo. + // If a "pending" content offset value has been set, we restore that value. + // Upon call to scrollTo, the "pending" values will be re-set. int scrollToX = pendingContentOffsetX != UNSET_CONTENT_OFFSET ? pendingContentOffsetX : getScrollX(); int scrollToY = @@ -954,23 +954,21 @@ public void reactSmoothScrollTo(int x, int y) { } /** - * Calls `reactScrollTo` and updates state. + * Calls `updateFabricScrollState` and updates state. * - *

`reactScrollTo` changes `contentOffset` and we need to keep `contentOffset` in sync between - * scroll view and state. Calling raw `reactScrollTo` doesn't update state. - * - *

Note that while we can override scrollTo, we *cannot* override `smoothScrollTo` because it - * is final. See `reactSmoothScrollTo`. + *

`scrollTo` changes `contentOffset` and we need to keep `contentOffset` in sync between + * scroll view and state. Calling ScrollView's `scrollTo` doesn't update state. */ @Override public void scrollTo(int x, int y) { super.scrollTo(x, y); - // The final scroll position might be different from (x, y). For example, we may need to scroll - // 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.updateFabricScrollState(this, actualX, actualY); - setPendingContentOffsets(actualX, actualY); + ReactScrollViewHelper.updateFabricScrollState(this); + setPendingContentOffsets(x, y); + } + + private boolean isContentReady() { + View child = getChildAt(0); + return child != null && child.getWidth() != 0 && child.getHeight() != 0; } /** @@ -981,8 +979,7 @@ public void scrollTo(int x, int y) { * @param y */ private void setPendingContentOffsets(int x, int y) { - View child = getChildAt(0); - if (child != null && child.getWidth() != 0 && child.getHeight() != 0) { + if (isContentReady()) { pendingContentOffsetX = UNSET_CONTENT_OFFSET; pendingContentOffsetY = UNSET_CONTENT_OFFSET; } else {