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
This commit is contained in:
Joshua Gross
2022-06-03 10:21:40 -07:00
committed by Facebook GitHub Bot
parent 00751f64c7
commit 11141b8b3c
@@ -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 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
}
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;