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

Android TextView: Moved Duplicate Code to single place #12892

Closed
wants to merge 14 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ public void setTextIsSelectable(boolean selectable) {

@Override
protected boolean verifyDrawable(Drawable drawable) {
if (mContainsImages && getText() instanceof Spanned) {
Spanned text = (Spanned) getText();
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
if (mContainsImages) {
TextInlineImageSpan[] spans = getTextInlineImageSpan();
for (TextInlineImageSpan span : spans) {
if (span.getDrawable() == drawable) {
return true;
Expand All @@ -144,9 +143,8 @@ protected boolean verifyDrawable(Drawable drawable) {

@Override
public void invalidateDrawable(Drawable drawable) {
if (mContainsImages && getText() instanceof Spanned) {
Spanned text = (Spanned) getText();
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
if (mContainsImages) {
TextInlineImageSpan[] spans = getTextInlineImageSpan();
for (TextInlineImageSpan span : spans) {
if (span.getDrawable() == drawable) {
invalidate();
Expand All @@ -159,9 +157,8 @@ public void invalidateDrawable(Drawable drawable) {
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (mContainsImages && getText() instanceof Spanned) {
Spanned text = (Spanned) getText();
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
if (mContainsImages) {
TextInlineImageSpan[] spans = getTextInlineImageSpan();
for (TextInlineImageSpan span : spans) {
span.onDetachedFromWindow();
}
Expand All @@ -171,9 +168,8 @@ public void onDetachedFromWindow() {
@Override
public void onStartTemporaryDetach() {
super.onStartTemporaryDetach();
if (mContainsImages && getText() instanceof Spanned) {
Spanned text = (Spanned) getText();
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
if (mContainsImages) {
TextInlineImageSpan[] spans = getTextInlineImageSpan();
for (TextInlineImageSpan span : spans) {
span.onStartTemporaryDetach();
}
Expand All @@ -183,23 +179,21 @@ public void onStartTemporaryDetach() {
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
if (mContainsImages && getText() instanceof Spanned) {
Spanned text = (Spanned) getText();
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
if (mContainsImages) {
TextInlineImageSpan[] spans = getTextInlineImageSpan();
for (TextInlineImageSpan span : spans) {
span.onAttachedToWindow();
span.onAttachedToWindow();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Remove extra whitespace please.

}
}
}

@Override
public void onFinishTemporaryDetach() {
super.onFinishTemporaryDetach();
if (mContainsImages && getText() instanceof Spanned) {
Spanned text = (Spanned) getText();
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);
if (mContainsImages) {
TextInlineImageSpan[] spans = getTextInlineImageSpan();
for (TextInlineImageSpan span : spans) {
span.onFinishTemporaryDetach();
span.onFinishTemporaryDetach();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Remove extra whitespace please.

}
}
}
Expand Down Expand Up @@ -279,4 +273,12 @@ private ReactViewBackgroundDrawable getOrCreateReactViewBackground() {
}
return mReactBackgroundDrawable;
}

private TextInlineImageSpan[] getTextInlineImageSpan() {
if (getText() instanceof Spanned) {
Spanned text = (Spanned) getText();
return text.getSpans(0, text.length(), TextInlineImageSpan.class);
}
return new TextInlineImageSpan[] { };
}
}