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
This commit is contained in:
Andrei Coman 2016-01-21 15:32:18 -08:00 committed by facebook-github-bot-5
parent 89207a1171
commit 2a70c53947
1 changed files with 5 additions and 0 deletions

View File

@ -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);