Skip to content

Commit

Permalink
Fix text in ReactTextView being vertically displayed
Browse files Browse the repository at this point in the history
Summary:
## Issue:
Sometimes ReactTextView are vertically displayed as one column with bridgeless.

## Root cause:
After debugging, I found out this is caused by a workaround in 2016 to fix a crash caused by mLayout occasionally being non-null and triggers relayout during setText.

facebook#7011

## Fix
Revert previous hack, if the crash happens again I'll try to fix it.

Changelog:
[Android][Fixed] -  Fix text in ReactTextView sometimes being vertically displayed

Reviewed By: mdvacca

Differential Revision: D26581756

fbshipit-source-id: a373d84dc1ab3d787bda7ec82f2d0865a354cf60
  • Loading branch information
luluwu2032 authored and facebook-github-bot committed Feb 24, 2021
1 parent 013b39f commit 86321a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ public class ReactFeatureFlags {

/** Enables a more aggressive cleanup during destruction of ReactContext */
public static boolean enableReactContextCleanupFix = false;

/** Enables setting layout params to empty to fix a crash */
public static boolean enableSettingEmptyLayoutParams = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.ReactCompoundView;
import com.facebook.react.uimanager.UIManagerModule;
Expand Down Expand Up @@ -265,11 +266,13 @@ public int compare(Object o1, Object o2) {

public void setText(ReactTextUpdate update) {
mContainsImages = update.containsImages();
// 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) {
setLayoutParams(EMPTY_LAYOUT_PARAMS);
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) {
setLayoutParams(EMPTY_LAYOUT_PARAMS);
}
}
Spannable spannable = update.getText();
if (mLinkifyMaskType > 0) {
Expand Down

0 comments on commit 86321a3

Please sign in to comment.