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 fa8f87710b1b8f..4c2a4d5fabd42b 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 @@ -79,18 +79,19 @@ public void setText(ReactTextUpdate update) { @Override public int reactTagForTouch(float touchX, float touchY) { - Spanned text = (Spanned) getText(); - int target = getId(); - - int x = (int) touchX; - int y = (int) touchY; - Layout layout = getLayout(); - if (layout == null) { + int target = getId(); + + if (layout == null || !(getText() instanceof Spanned)) { // 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 x = (int) touchX; + int y = (int) touchY; + + Spanned text = (Spanned) getText(); int line = layout.getLineForVertical(y); int lineStartX = (int) layout.getLineLeft(line);