Fix Nodes crash when text is not spanned

Summary:
A Layout's text can either be an Ellipsizer or a SpannedEllipsizer.
SpannedEllipsizer implements Spannable, but Ellipsizer doesn't. We were
casting the Layout's text directly to a Spanned without first checking as to
whether or not it was actually a Spanned.

Reviewed By: sriramramani

Differential Revision: D3435075
This commit is contained in:
Ahmed El-Helw 2016-06-16 13:25:58 -07:00
Родитель fc622504de
Коммит f0734c141f
1 изменённых файлов: 13 добавлений и 10 удалений

Просмотреть файл

@ -39,19 +39,22 @@ import android.text.Spanned;
/* package */ int getReactTag(float touchX, float touchY) {
if (mLayout != null) {
int y = Math.round(touchY - mTop);
if (y >= mLayout.getLineTop(0) && y < mLayout.getLineBottom(mLayout.getLineCount() - 1)) {
float x = Math.round(touchX - mLeft);
int line = mLayout.getLineForVertical(y);
CharSequence text = mLayout.getText();
if (text instanceof Spanned) {
int y = Math.round(touchY - mTop);
if (y >= mLayout.getLineTop(0) && y < mLayout.getLineBottom(mLayout.getLineCount() - 1)) {
float x = Math.round(touchX - mLeft);
int line = mLayout.getLineForVertical(y);
if (mLayout.getLineLeft(line) <= x && x <= mLayout.getLineRight(line)) {
int off = mLayout.getOffsetForHorizontal(line, x);
if (mLayout.getLineLeft(line) <= x && x <= mLayout.getLineRight(line)) {
int off = mLayout.getOffsetForHorizontal(line, x);
Spanned text = (Spanned) mLayout.getText();
RCTRawText[] link = text.getSpans(off, off, RCTRawText.class);
Spanned spanned = (Spanned) text;
RCTRawText[] link = spanned.getSpans(off, off, RCTRawText.class);
if (link.length != 0) {
return link[0].getReactTag();
if (link.length != 0) {
return link[0].getReactTag();
}
}
}
}