Fix text in ReactTextView being vertically displayed

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.

https://github.com/facebook/react-native/pull/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
This commit is contained in:
Lulu Wu
2021-02-24 12:19:07 -08:00
committed by Facebook GitHub Bot
parent 013b39f32c
commit 86321a35c0
2 changed files with 11 additions and 5 deletions
@@ -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;
}
@@ -31,6 +31,7 @@ import com.facebook.react.bridge.ReactContext;
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;
@@ -265,11 +266,13 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
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) {