Skip to content

Commit

Permalink
Test setting layout params to wrap_content for fix text layout bug
Browse files Browse the repository at this point in the history
Summary:
Changelog:
[Android][Fixed] -  Fix layout bug in ReactTextView.

Reviewed By: mdvacca

Differential Revision: D26752392

fbshipit-source-id: eeb9c16a4165b4d9329534981925621ae51a7dcb
  • Loading branch information
luluwu2032 authored and facebook-github-bot committed Mar 2, 2021
1 parent 62fcb4e commit dec1b6b
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
private static final ViewGroup.LayoutParams EMPTY_LAYOUT_PARAMS =
new ViewGroup.LayoutParams(0, 0);

private static final ViewGroup.LayoutParams WRAP_CONTENT_LAYOUT_PARAMS =
new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

private boolean mContainsImages;
private int mDefaultGravityHorizontal;
private int mDefaultGravityVertical;
Expand Down Expand Up @@ -266,12 +270,14 @@ public int compare(Object o1, Object o2) {

public void setText(ReactTextUpdate update) {
mContainsImages = update.containsImages();
if (ReactFeatureFlags.enableSettingEmptyLayoutParams) {
// Android's TextView crashes when it tries to relayout if LayoutParams are
// null; explicitly set the LayoutParams to prevent this crash. See:
// https://github.com/facebook/react-native/pull/7011
if (getLayoutParams() == null) {
// Android's TextView crashes when it tries to relayout if LayoutParams are
// null; explicitly set the LayoutParams to prevent this crash. See:
// https://github.com/facebook/react-native/pull/7011
if (getLayoutParams() == null) {
if (ReactFeatureFlags.enableSettingEmptyLayoutParams) {
setLayoutParams(EMPTY_LAYOUT_PARAMS);
} else {
setLayoutParams(WRAP_CONTENT_LAYOUT_PARAMS);
}
}
Spannable spannable = update.getText();
Expand Down

0 comments on commit dec1b6b

Please sign in to comment.