Skip to content

Commit

Permalink
Minimize EditText Spans 4/9: ReactForegroundColorSpan (facebook#36545)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#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]( facebook#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: 8d8a92f704241c1592454c1e57ff74d4a58c0816
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Mar 22, 2023
1 parent 3027f64 commit fd4a7d2
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.facebook.react.views.text.CustomStyleSpan;
import com.facebook.react.views.text.ReactAbsoluteSizeSpan;
import com.facebook.react.views.text.ReactBackgroundColorSpan;
import com.facebook.react.views.text.ReactForegroundColorSpan;
import com.facebook.react.views.text.ReactSpan;
import com.facebook.react.views.text.ReactTextUpdate;
import com.facebook.react.views.text.ReactTypefaceUtils;
Expand Down Expand Up @@ -692,6 +693,16 @@ public boolean test(ReactBackgroundColorSpan span) {
return span.getBackgroundColor() == mReactBackgroundManager.getBackgroundColor();
}
});

stripSpansOfKind(
sb,
ReactForegroundColorSpan.class,
new SpanPredicate<ReactForegroundColorSpan>() {
@Override
public boolean test(ReactForegroundColorSpan span) {
return span.getForegroundColor() == getCurrentTextColor();
}
});
}

private <T> void stripSpansOfKind(
Expand Down Expand Up @@ -731,6 +742,7 @@ private void restoreStyleEquivalentSpans(SpannableStringBuilder workingText) {

List<Object> spans = new ArrayList<>();
spans.add(new ReactAbsoluteSizeSpan(mTextAttributes.getEffectiveFontSize()));
spans.add(new ReactForegroundColorSpan(getCurrentTextColor()));

int backgroundColor = mReactBackgroundManager.getBackgroundColor();
if (backgroundColor != Color.TRANSPARENT) {
Expand Down

0 comments on commit fd4a7d2

Please sign in to comment.