Skip to content

Commit

Permalink
Return early from textview layout pass if text layout is null
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Andrei Shikov authored and facebook-github-bot committed Jul 12, 2021
1 parent ca440b9 commit 8dfc3bc
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ protected void onLayout(

Spanned text = (Spanned) getText();
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 =
text.getSpans(0, text.length(), TextInlineViewPlaceholderSpan.class);
ArrayList inlineViewInfoArray =
Expand Down

0 comments on commit 8dfc3bc

Please sign in to comment.