From 8dfc3bcda1e77fc982bc98da20dc129c23d8cc77 Mon Sep 17 00:00:00 2001 From: Andrei Shikov Date: Mon, 12 Jul 2021 06:05:54 -0700 Subject: [PATCH] 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 --- .../com/facebook/react/views/text/ReactTextView.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java index f7a0a18995fe75..7ce861de7bfdff 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java @@ -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 =