Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ClassCastException in TextInput #12886

Closed
wants to merge 12 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do not call getText twice here?

// 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);
Expand Down