|
11 | 11 | import static com.facebook.react.views.text.TextAttributeProps.UNSET;
|
12 | 12 |
|
13 | 13 | import android.content.Context;
|
| 14 | +import android.graphics.Color; |
14 | 15 | import android.graphics.Rect;
|
15 | 16 | import android.graphics.Typeface;
|
16 | 17 | import android.graphics.drawable.Drawable;
|
|
50 | 51 | import com.facebook.react.views.text.CustomLineHeightSpan;
|
51 | 52 | import com.facebook.react.views.text.CustomStyleSpan;
|
52 | 53 | import com.facebook.react.views.text.ReactAbsoluteSizeSpan;
|
| 54 | +import com.facebook.react.views.text.ReactBackgroundColorSpan; |
53 | 55 | import com.facebook.react.views.text.ReactSpan;
|
54 | 56 | import com.facebook.react.views.text.ReactTextUpdate;
|
55 | 57 | import com.facebook.react.views.text.ReactTypefaceUtils;
|
@@ -680,6 +682,16 @@ public boolean test(ReactAbsoluteSizeSpan span) {
|
680 | 682 | return span.getSize() == mTextAttributes.getEffectiveFontSize();
|
681 | 683 | }
|
682 | 684 | });
|
| 685 | + |
| 686 | + stripSpansOfKind( |
| 687 | + sb, |
| 688 | + ReactBackgroundColorSpan.class, |
| 689 | + new SpanPredicate<ReactBackgroundColorSpan>() { |
| 690 | + @Override |
| 691 | + public boolean test(ReactBackgroundColorSpan span) { |
| 692 | + return span.getBackgroundColor() == mReactBackgroundManager.getBackgroundColor(); |
| 693 | + } |
| 694 | + }); |
683 | 695 | }
|
684 | 696 |
|
685 | 697 | private <T> void stripSpansOfKind(
|
@@ -717,11 +729,17 @@ private void restoreStyleEquivalentSpans(SpannableStringBuilder workingText) {
|
717 | 729 | // (least precedence). This ensures the span is behind any overlapping spans.
|
718 | 730 | spanFlags |= Spannable.SPAN_PRIORITY;
|
719 | 731 |
|
720 |
| - workingText.setSpan( |
721 |
| - new ReactAbsoluteSizeSpan(mTextAttributes.getEffectiveFontSize()), |
722 |
| - 0, |
723 |
| - workingText.length(), |
724 |
| - spanFlags); |
| 732 | + List<Object> spans = new ArrayList<>(); |
| 733 | + spans.add(new ReactAbsoluteSizeSpan(mTextAttributes.getEffectiveFontSize())); |
| 734 | + |
| 735 | + int backgroundColor = mReactBackgroundManager.getBackgroundColor(); |
| 736 | + if (backgroundColor != Color.TRANSPARENT) { |
| 737 | + spans.add(new ReactBackgroundColorSpan(backgroundColor)); |
| 738 | + } |
| 739 | + |
| 740 | + for (Object span : spans) { |
| 741 | + workingText.setSpan(span, 0, workingText.length(), spanFlags); |
| 742 | + } |
725 | 743 | }
|
726 | 744 |
|
727 | 745 | private static boolean sameTextForSpan(
|
|
0 commit comments