Set LayoutParams in ReactTextView to fix crash
Summary: ReactTextView occasionally crashes when `setText` is called. Doing some cursory research, it looks like this could be a bug in Android. We also suspect it might be related to removeClippedSubviews though. The LayoutParams don't actually matter because RN controls layout, but on occasion (haven't narrowed down what this is...) `mLayout` is non-null and triggers relayout during `setText`, which fails because the LayoutParams are null. jesseruder came up with this fix and it appears to be working well. Stack trace: http://pastebin.com/P8VbxvPz Closes https://github.com/facebook/react-native/pull/7011 Differential Revision: D3508097 fbshipit-source-id: 12b4aa11e42112c8ba19a1af325e3ee9a232d08f
This commit is contained in:
parent
d1d9045eb4
commit
a8011bbfdc
|
@ -14,12 +14,16 @@ import android.graphics.drawable.Drawable;
|
|||
import android.text.Layout;
|
||||
import android.text.Spanned;
|
||||
import android.view.Gravity;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.facebook.react.uimanager.ReactCompoundView;
|
||||
|
||||
public class ReactTextView extends TextView implements ReactCompoundView {
|
||||
|
||||
private static final ViewGroup.LayoutParams EMPTY_LAYOUT_PARAMS =
|
||||
new ViewGroup.LayoutParams(0, 0);
|
||||
|
||||
private boolean mContainsImages;
|
||||
private int mDefaultGravityHorizontal;
|
||||
private int mDefaultGravityVertical;
|
||||
|
@ -34,6 +38,12 @@ public class ReactTextView extends TextView implements ReactCompoundView {
|
|||
|
||||
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);
|
||||
}
|
||||
setText(update.getText());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue