diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollContainerView.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollContainerView.java index 0445fbdf36cf4a..fcd473f4edd62c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollContainerView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollContainerView.java @@ -44,13 +44,6 @@ public void setRemoveClippedSubviews(boolean removeClippedSubviews) { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - /** - * Note: in RTL mode, *when layout width changes*, we adjust the scroll position. Practically, - * this means that on the first (meaningful) layout we will go from position 0 to position - * (right - screenWidth). In theory this means if the width of the view ever changes during - * layout again, scrolling could jump. Which shouldn't happen in theory, but... if you find a - * weird product bug that looks related, keep this in mind. - */ if (mLayoutDirection == LAYOUT_DIRECTION_RTL) { // When the layout direction is RTL, we expect Yoga to give us a layout // that extends off the screen to the left so we re-center it with left=0 @@ -60,11 +53,20 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto setLeft(newLeft); setRight(newRight); - // Call with the present values in order to re-layout if necessary - ReactHorizontalScrollView parent = (ReactHorizontalScrollView) getParent(); - // Fix the ScrollX position when using RTL language - int offsetX = parent.getScrollX() + getWidth() - mCurrentWidth; - parent.reactScrollTo(offsetX, parent.getScrollY()); + /** + * Note: in RTL mode, *when layout width changes*, we adjust the scroll position. Practically, + * this means that on the first (meaningful) layout we will go from position 0 to position + * (right - screenWidth). In theory this means if the width of the view ever changes during + * layout again, scrolling could jump. Which shouldn't happen in theory, but... if you find a + * weird product bug that looks related, keep this in mind. + */ + if (mCurrentWidth != getWidth()) { + // Call with the present values in order to re-layout if necessary + ReactHorizontalScrollView parent = (ReactHorizontalScrollView) getParent(); + // Fix the ScrollX position when using RTL language + int offsetX = parent.getScrollX() + getWidth() - mCurrentWidth; + parent.reactScrollTo(offsetX, parent.getScrollY()); + } } mCurrentWidth = getWidth(); }