Skip to content

Commit 104cb7f

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Minimize EditText Spans 7/9: Avoid temp list (#36576)
Summary: Pull Request resolved: #36576 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. Changelog: [Internal] Reviewed By: javache Differential Revision: D44295190 fbshipit-source-id: bd784e2c514301d45d0bacd8ee6de5c512fc565c
1 parent 5791cf1 commit 104cb7f

File tree

1 file changed

+17
-11
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput

1 file changed

+17
-11
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -762,33 +762,39 @@ private void restoreStyleEquivalentSpans(SpannableStringBuilder workingText) {
762762
// (least precedence). This ensures the span is behind any overlapping spans.
763763
spanFlags |= Spannable.SPAN_PRIORITY;
764764

765-
List<Object> spans = new ArrayList<>();
766-
spans.add(new ReactAbsoluteSizeSpan(mTextAttributes.getEffectiveFontSize()));
767-
spans.add(new ReactForegroundColorSpan(getCurrentTextColor()));
765+
workingText.setSpan(
766+
new ReactAbsoluteSizeSpan(mTextAttributes.getEffectiveFontSize()),
767+
0,
768+
workingText.length(),
769+
spanFlags);
770+
771+
workingText.setSpan(
772+
new ReactForegroundColorSpan(getCurrentTextColor()), 0, workingText.length(), spanFlags);
768773

769774
int backgroundColor = mReactBackgroundManager.getBackgroundColor();
770775
if (backgroundColor != Color.TRANSPARENT) {
771-
spans.add(new ReactBackgroundColorSpan(backgroundColor));
776+
workingText.setSpan(
777+
new ReactBackgroundColorSpan(backgroundColor), 0, workingText.length(), spanFlags);
772778
}
773779

774780
if ((getPaintFlags() & Paint.STRIKE_THRU_TEXT_FLAG) != 0) {
775-
spans.add(new ReactStrikethroughSpan());
781+
workingText.setSpan(new ReactStrikethroughSpan(), 0, workingText.length(), spanFlags);
776782
}
777783

778784
if ((getPaintFlags() & Paint.UNDERLINE_TEXT_FLAG) != 0) {
779-
spans.add(new ReactUnderlineSpan());
785+
workingText.setSpan(new ReactUnderlineSpan(), 0, workingText.length(), spanFlags);
780786
}
781787

782788
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
783789
float effectiveLetterSpacing = mTextAttributes.getEffectiveLetterSpacing();
784790
if (!Float.isNaN(effectiveLetterSpacing)) {
785-
spans.add(new CustomLetterSpacingSpan(effectiveLetterSpacing));
791+
workingText.setSpan(
792+
new CustomLetterSpacingSpan(effectiveLetterSpacing),
793+
0,
794+
workingText.length(),
795+
spanFlags);
786796
}
787797
}
788-
789-
for (Object span : spans) {
790-
workingText.setSpan(span, 0, workingText.length(), spanFlags);
791-
}
792798
}
793799

794800
private static boolean sameTextForSpan(

0 commit comments

Comments
 (0)