From 2a70c539477996e2dad6e4a4ddd6a794035c5697 Mon Sep 17 00:00:00 2001 From: Andrei Coman Date: Thu, 21 Jan 2016 15:32:18 -0800 Subject: [PATCH] Don't NPE in reactTagForTouch Summary: This NPEs because the layout is null if the TextView has recently changed. However, this also means that the TextView hasn't been laid out yet, so the default TextView tag is correct. public Reviewed By: oli Differential Revision: D2848412 fb-gh-sync-id: 5faf793d17f50283c153dc0d43fb717e8764cb7d --- .../java/com/facebook/react/views/text/ReactTextView.java | 5 +++++ 1 file changed, 5 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 faea8bad4..8c7e7f948 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 @@ -39,6 +39,11 @@ public class ReactTextView extends TextView implements ReactCompoundView { int y = (int) touchY; Layout layout = getLayout(); + if (layout == null) { + // If the layout is null, the view hasn't been properly laid out yet. Therefore, we can't find + // the exact text tag that has been touched, and the correct tag to return is the default one. + return target; + } int line = layout.getLineForVertical(y); int lineStartX = (int) layout.getLineLeft(line);