From b71a4a8ee9a3b571076e9faa218fb74fc4180097 Mon Sep 17 00:00:00 2001 From: guptasourabh Date: Sun, 12 Mar 2017 23:07:38 +0530 Subject: [PATCH] ClassCastException ClassCastException happening if getText() is String Fatal Exception: java.lang.ClassCastException: java.lang.String cannot be cast to android.text.Spanned at com.facebook.react.views.text.ReactTextView.reactTagForTouch(ReactTextView.java:52) at com.facebook.react.uimanager.TouchTargetHelper.getTouchTargetForView(TouchTargetHelper.java:257) at com.facebook.react.uimanager.TouchTargetHelper.findTargetTagAndCoordinatesForTouch(TouchTargetHelper.java:101) at com.facebook.react.uimanager.JSTouchDispatcher.handleTouchEvent(JSTouchDispatcher.java:76) --- .../facebook/react/views/text/ReactTextView.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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 3d5d9668bd8106..077824f0be648e 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);