Skip to content

Commit

Permalink
Minimize EditText Spans 7/N: Avoid temp list
Browse files Browse the repository at this point in the history
Summary:
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 change addresses some minor CR feedback and removes the temporary list of spans in favor of applying them directly.

Differential Revision: D44295190

fbshipit-source-id: 96a03a3cb323d47af5196efb091698c09daf9a13
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Mar 24, 2023
1 parent a954f87 commit 45c445b
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -762,33 +762,39 @@ private void restoreStyleEquivalentSpans(SpannableStringBuilder workingText) {
// (least precedence). This ensures the span is behind any overlapping spans.
spanFlags |= Spannable.SPAN_PRIORITY;

List<Object> spans = new ArrayList<>();
spans.add(new ReactAbsoluteSizeSpan(mTextAttributes.getEffectiveFontSize()));
spans.add(new ReactForegroundColorSpan(getCurrentTextColor()));
workingText.setSpan(
new ReactAbsoluteSizeSpan(mTextAttributes.getEffectiveFontSize()),
0,
workingText.length(),
spanFlags);

workingText.setSpan(
new ReactForegroundColorSpan(getCurrentTextColor()), 0, workingText.length(), spanFlags);

int backgroundColor = mReactBackgroundManager.getBackgroundColor();
if (backgroundColor != Color.TRANSPARENT) {
spans.add(new ReactBackgroundColorSpan(backgroundColor));
workingText.setSpan(
new ReactBackgroundColorSpan(backgroundColor), 0, workingText.length(), spanFlags);
}

if ((getPaintFlags() & Paint.STRIKE_THRU_TEXT_FLAG) != 0) {
spans.add(new ReactStrikethroughSpan());
workingText.setSpan(new ReactStrikethroughSpan(), 0, workingText.length(), spanFlags);
}

if ((getPaintFlags() & Paint.UNDERLINE_TEXT_FLAG) != 0) {
spans.add(new ReactUnderlineSpan());
workingText.setSpan(new ReactUnderlineSpan(), 0, workingText.length(), spanFlags);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
float effectiveLetterSpacing = mTextAttributes.getEffectiveLetterSpacing();
if (!Float.isNaN(effectiveLetterSpacing)) {
spans.add(new CustomLetterSpacingSpan(effectiveLetterSpacing));
workingText.setSpan(
new CustomLetterSpacingSpan(effectiveLetterSpacing),
0,
workingText.length(),
spanFlags);
}
}

for (Object span : spans) {
workingText.setSpan(span, 0, workingText.length(), spanFlags);
}
}

private static boolean sameTextForSpan(
Expand Down

0 comments on commit 45c445b

Please sign in to comment.