Skip to content

Commit dec1b6b

Browse files
luluwu2032facebook-github-bot
authored andcommitted
Test setting layout params to wrap_content for fix text layout bug
Summary: Changelog: [Android][Fixed] - Fix layout bug in ReactTextView. Reviewed By: mdvacca Differential Revision: D26752392 fbshipit-source-id: eeb9c16a4165b4d9329534981925621ae51a7dcb
1 parent 62fcb4e commit dec1b6b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
4848
private static final ViewGroup.LayoutParams EMPTY_LAYOUT_PARAMS =
4949
new ViewGroup.LayoutParams(0, 0);
5050

51+
private static final ViewGroup.LayoutParams WRAP_CONTENT_LAYOUT_PARAMS =
52+
new ViewGroup.LayoutParams(
53+
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
54+
5155
private boolean mContainsImages;
5256
private int mDefaultGravityHorizontal;
5357
private int mDefaultGravityVertical;
@@ -266,12 +270,14 @@ public int compare(Object o1, Object o2) {
266270

267271
public void setText(ReactTextUpdate update) {
268272
mContainsImages = update.containsImages();
269-
if (ReactFeatureFlags.enableSettingEmptyLayoutParams) {
270-
// Android's TextView crashes when it tries to relayout if LayoutParams are
271-
// null; explicitly set the LayoutParams to prevent this crash. See:
272-
// https://github.com/facebook/react-native/pull/7011
273-
if (getLayoutParams() == null) {
273+
// Android's TextView crashes when it tries to relayout if LayoutParams are
274+
// null; explicitly set the LayoutParams to prevent this crash. See:
275+
// https://github.com/facebook/react-native/pull/7011
276+
if (getLayoutParams() == null) {
277+
if (ReactFeatureFlags.enableSettingEmptyLayoutParams) {
274278
setLayoutParams(EMPTY_LAYOUT_PARAMS);
279+
} else {
280+
setLayoutParams(WRAP_CONTENT_LAYOUT_PARAMS);
275281
}
276282
}
277283
Spannable spannable = update.getText();

0 commit comments

Comments
 (0)