Skip to content

Commit

Permalink
Fix alignment during recycling of ReactTextView
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JoshuaGross authored and facebook-github-bot committed Jun 3, 2022
1 parent 00751f6 commit 11141b8
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand All @@ -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;
Expand Down

0 comments on commit 11141b8

Please sign in to comment.