Skip to content

Commit b14713d

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: 243c40b1062d470e44e6c59df2f2146d850fbcd8
1 parent 786acf4 commit b14713d

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
@@ -775,33 +775,39 @@ private void restoreStyleEquivalentSpans(SpannableStringBuilder workingText) {
775775
// (least precedence). This ensures the span is behind any overlapping spans.
776776
spanFlags |= Spannable.SPAN_PRIORITY;
777777

778-
List<Object> spans = new ArrayList<>();
779-
spans.add(new ReactAbsoluteSizeSpan(mTextAttributes.getEffectiveFontSize()));
780-
spans.add(new ReactForegroundColorSpan(getCurrentTextColor()));
778+
workingText.setSpan(
779+
new ReactAbsoluteSizeSpan(mTextAttributes.getEffectiveFontSize()),
780+
0,
781+
workingText.length(),
782+
spanFlags);
783+
784+
workingText.setSpan(
785+
new ReactForegroundColorSpan(getCurrentTextColor()), 0, workingText.length(), spanFlags);
781786

782787
int backgroundColor = mReactBackgroundManager.getBackgroundColor();
783788
if (backgroundColor != Color.TRANSPARENT) {
784-
spans.add(new ReactBackgroundColorSpan(backgroundColor));
789+
workingText.setSpan(
790+
new ReactBackgroundColorSpan(backgroundColor), 0, workingText.length(), spanFlags);
785791
}
786792

787793
if ((getPaintFlags() & Paint.STRIKE_THRU_TEXT_FLAG) != 0) {
788-
spans.add(new ReactStrikethroughSpan());
794+
workingText.setSpan(new ReactStrikethroughSpan(), 0, workingText.length(), spanFlags);
789795
}
790796

791797
if ((getPaintFlags() & Paint.UNDERLINE_TEXT_FLAG) != 0) {
792-
spans.add(new ReactUnderlineSpan());
798+
workingText.setSpan(new ReactUnderlineSpan(), 0, workingText.length(), spanFlags);
793799
}
794800

795801
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
796802
float effectiveLetterSpacing = mTextAttributes.getEffectiveLetterSpacing();
797803
if (!Float.isNaN(effectiveLetterSpacing)) {
798-
spans.add(new CustomLetterSpacingSpan(effectiveLetterSpacing));
804+
workingText.setSpan(
805+
new CustomLetterSpacingSpan(effectiveLetterSpacing),
806+
0,
807+
workingText.length(),
808+
spanFlags);
799809
}
800810
}
801-
802-
for (Object span : spans) {
803-
workingText.setSpan(span, 0, workingText.length(), spanFlags);
804-
}
805811
}
806812

807813
private static boolean sameTextForSpan(

0 commit comments

Comments
 (0)