From 11141b8b3c1b95bcd11c62fc14938d131acd2119 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Fri, 3 Jun 2022 10:21:40 -0700 Subject: [PATCH] Fix alignment during recycling of ReactTextView Summary: In the constructor we should get the default gravity params (as we did previously) and then never change these; thus, we can also make these fields final. These are used in `initView` during construction and upon recycling to reset vertical and horizontal alignment to their defaults. Changelog: [Internal] Reviewed By: genkikondo Differential Revision: D36885646 fbshipit-source-id: 2f4d0b125b8645a380a08965e08db3ba1f12cae3 --- .../facebook/react/views/text/ReactTextView.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java index fcc81f8db88a75..1225830d38c391 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java @@ -52,8 +52,8 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie new ViewGroup.LayoutParams(0, 0); private boolean mContainsImages; - private int mDefaultGravityHorizontal; - private int mDefaultGravityVertical; + private final int mDefaultGravityHorizontal; + private final int mDefaultGravityVertical; private int mTextAlign; private int mNumberOfLines; private TextUtils.TruncateAt mEllipsizeLocation; @@ -67,6 +67,12 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie public ReactTextView(Context context) { super(context); + + // Get these defaults only during the constructor - these should never be set otherwise + mDefaultGravityHorizontal = + getGravity() & (Gravity.HORIZONTAL_GRAVITY_MASK | Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK); + mDefaultGravityVertical = getGravity() & Gravity.VERTICAL_GRAVITY_MASK; + initView(); } @@ -82,9 +88,6 @@ private void initView() { } mReactBackgroundManager = new ReactViewBackgroundManager(this); - mDefaultGravityHorizontal = - getGravity() & (Gravity.HORIZONTAL_GRAVITY_MASK | Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK); - mDefaultGravityVertical = getGravity() & Gravity.VERTICAL_GRAVITY_MASK; mTextAlign = Gravity.NO_GRAVITY; mNumberOfLines = ViewDefaults.NUMBER_OF_LINES;