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
This commit is contained in:
Andrei Shikov 2021-07-12 06:05:54 -07:00 коммит произвёл Facebook GitHub Bot
Родитель ca440b9100
Коммит 8dfc3bcda1
1 изменённых файлов: 11 добавлений и 0 удалений

Просмотреть файл

@ -124,6 +124,17 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
Spanned text = (Spanned) getText(); Spanned text = (Spanned) getText();
Layout layout = getLayout(); Layout layout = getLayout();
if (layout == null) {
// Text layout is calculated during pre-draw phase, so in some cases it can be empty during
// layout phase, which usually happens before drawing.
// The text layout is created by private {@link assumeLayout} method, which we can try to
// invoke directly through reflection or indirectly through some methods that compute it
// (e.g. {@link getExtendedPaddingTop}).
// It is safer, however, to just early return here, as next measure/layout passes are way more
// likely to have the text layout computed.
return;
}
TextInlineViewPlaceholderSpan[] placeholders = TextInlineViewPlaceholderSpan[] placeholders =
text.getSpans(0, text.length(), TextInlineViewPlaceholderSpan.class); text.getSpans(0, text.length(), TextInlineViewPlaceholderSpan.class);
ArrayList inlineViewInfoArray = ArrayList inlineViewInfoArray =