Browse files

Fix Horizontal ScrollView's scroll position during layout changes

Summary: Fix the calculation of offsetX in onLayout ( that re-positions the updated layout. A private instance variable (oldWidth) is added in order to track the width difference between consecutive updates. (Issue report: #19979)

Reviewed By: mdvacca

Differential Revision: D8772780

fbshipit-source-id: 969dcead550f4a3d24d06416b63d960492b7a124
  • Loading branch information...
Jiaqi Wu authored and facebook-github-bot committed Jul 20, 2018
1 parent 1b2a552 commit de573277bf64703aefdeb52db2c2524b2c241bab
@@ -14,11 +14,13 @@
public class ReactHorizontalScrollContainerView extends ViewGroup {
private int mLayoutDirection;
private int mCurrentWidth;
public ReactHorizontalScrollContainerView(Context context) {
mLayoutDirection =
I18nUtil.getInstance().isRTL(context) ? LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR;
mCurrentWidth = 0;
@@ -32,12 +34,12 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
// 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();

0 comments on commit de57327

Please sign in to comment.