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 bcda656077c606..e23e53305a90ab 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 @@ -14,11 +14,13 @@ public class ReactHorizontalScrollContainerView extends ViewGroup { private int mLayoutDirection; + private int mCurrentWidth; public ReactHorizontalScrollContainerView(Context context) { super(context); mLayoutDirection = I18nUtil.getInstance().isRTL(context) ? LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; + mCurrentWidth = 0; } @Override @@ -32,12 +34,12 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto setLeft(newLeft); setRight(newRight); - // Fix the ScrollX position when using RTL language - int offsetX = computeHorizontalScrollRange() - getScrollX(); - // Call with the present values in order to re-layout if necessary HorizontalScrollView parent = (HorizontalScrollView) getParent(); + // Fix the ScrollX position when using RTL language + int offsetX = parent.getScrollX() + getWidth() - mCurrentWidth; parent.scrollTo(offsetX, parent.getScrollY()); } + mCurrentWidth = getWidth(); } }