Skip to content

Commit 8dfc3bc

Browse files
Andrei Shikovfacebook-github-bot
Andrei Shikov
authored andcommitted
Return early from textview layout pass if text layout is null
Summary: Could not repro myself, but logview shows steady low number of crashes coming from this mid. Current fix returns early if the layout is not defined, relying on the following layout passes to position view correctly. Changelog: [Android][Fixed] Exit early from layout in textview if text layout is null Reviewed By: JoshuaGross Differential Revision: D29636040 fbshipit-source-id: 876ce80222cbc5ff09450224f6808f9f6433c62a
1 parent ca440b9 commit 8dfc3bc

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

+11
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ protected void onLayout(
124124

125125
Spanned text = (Spanned) getText();
126126
Layout layout = getLayout();
127+
if (layout == null) {
128+
// Text layout is calculated during pre-draw phase, so in some cases it can be empty during
129+
// layout phase, which usually happens before drawing.
130+
// The text layout is created by private {@link assumeLayout} method, which we can try to
131+
// invoke directly through reflection or indirectly through some methods that compute it
132+
// (e.g. {@link getExtendedPaddingTop}).
133+
// It is safer, however, to just early return here, as next measure/layout passes are way more
134+
// likely to have the text layout computed.
135+
return;
136+
}
137+
127138
TextInlineViewPlaceholderSpan[] placeholders =
128139
text.getSpans(0, text.length(), TextInlineViewPlaceholderSpan.class);
129140
ArrayList inlineViewInfoArray =

0 commit comments

Comments
 (0)