Skip to content

Commit 11141b8

Browse files
JoshuaGrossfacebook-github-bot
authored andcommitted
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
1 parent 00751f6 commit 11141b8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
5252
new ViewGroup.LayoutParams(0, 0);
5353

5454
private boolean mContainsImages;
55-
private int mDefaultGravityHorizontal;
56-
private int mDefaultGravityVertical;
55+
private final int mDefaultGravityHorizontal;
56+
private final int mDefaultGravityVertical;
5757
private int mTextAlign;
5858
private int mNumberOfLines;
5959
private TextUtils.TruncateAt mEllipsizeLocation;
@@ -67,6 +67,12 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
6767

6868
public ReactTextView(Context context) {
6969
super(context);
70+
71+
// Get these defaults only during the constructor - these should never be set otherwise
72+
mDefaultGravityHorizontal =
73+
getGravity() & (Gravity.HORIZONTAL_GRAVITY_MASK | Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK);
74+
mDefaultGravityVertical = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
75+
7076
initView();
7177
}
7278

@@ -82,9 +88,6 @@ private void initView() {
8288
}
8389

8490
mReactBackgroundManager = new ReactViewBackgroundManager(this);
85-
mDefaultGravityHorizontal =
86-
getGravity() & (Gravity.HORIZONTAL_GRAVITY_MASK | Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK);
87-
mDefaultGravityVertical = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
8891

8992
mTextAlign = Gravity.NO_GRAVITY;
9093
mNumberOfLines = ViewDefaults.NUMBER_OF_LINES;

0 commit comments

Comments
 (0)