Skip to content

Commit ab6be34

Browse files
NickGerlemankelset
authored andcommittedApr 19, 2023
Minimize EditText Spans 4/9: ReactForegroundColorSpan (#36545)
Summary: Pull Request resolved: #36545 This is part of a series of changes to minimize the number of spans committed to EditText, as a mitigation for platform issues on Samsung devices. See this [GitHub thread]( #35936 (comment)) for greater context on the platform behavior. This adds ReactForegroundColorSpan to the list of spans eligible to be stripped. Changelog: [Android][Fixed] - Minimize Spans 4/N: ReactForegroundColorSpan Reviewed By: javache Differential Revision: D44240780 fbshipit-source-id: d86939cc2d7ed9116a4167026c7d48928fc51757
1 parent e7e2556 commit ab6be34

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
 

‎ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java

+12
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import com.facebook.react.views.text.CustomStyleSpan;
5353
import com.facebook.react.views.text.ReactAbsoluteSizeSpan;
5454
import com.facebook.react.views.text.ReactBackgroundColorSpan;
55+
import com.facebook.react.views.text.ReactForegroundColorSpan;
5556
import com.facebook.react.views.text.ReactSpan;
5657
import com.facebook.react.views.text.ReactTextUpdate;
5758
import com.facebook.react.views.text.ReactTypefaceUtils;
@@ -657,6 +658,16 @@ public boolean test(ReactBackgroundColorSpan span) {
657658
return span.getBackgroundColor() == mReactBackgroundManager.getBackgroundColor();
658659
}
659660
});
661+
662+
stripSpansOfKind(
663+
sb,
664+
ReactForegroundColorSpan.class,
665+
new SpanPredicate<ReactForegroundColorSpan>() {
666+
@Override
667+
public boolean test(ReactForegroundColorSpan span) {
668+
return span.getForegroundColor() == getCurrentTextColor();
669+
}
670+
});
660671
}
661672

662673
private <T> void stripSpansOfKind(
@@ -683,6 +694,7 @@ private void restoreStyleEquivalentSpans(SpannableStringBuilder workingText) {
683694

684695
List<Object> spans = new ArrayList<>();
685696
spans.add(new ReactAbsoluteSizeSpan(mTextAttributes.getEffectiveFontSize()));
697+
spans.add(new ReactForegroundColorSpan(getCurrentTextColor()));
686698

687699
int backgroundColor = mReactBackgroundManager.getBackgroundColor();
688700
if (backgroundColor != Color.TRANSPARENT) {

0 commit comments

Comments
 (0)
Please sign in to comment.