Skip to content

Commit 4b9b203

Browse files
NickGerlemankelset
authored andcommittedApr 19, 2023
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 64eeb81 commit 4b9b203

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed
 

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

+17-11
Original file line numberDiff line numberDiff line change
@@ -727,33 +727,39 @@ private void restoreStyleEquivalentSpans(SpannableStringBuilder workingText) {
727727
// (least precedence). This ensures the span is behind any overlapping spans.
728728
spanFlags |= Spannable.SPAN_PRIORITY;
729729

730-
List<Object> spans = new ArrayList<>();
731-
spans.add(new ReactAbsoluteSizeSpan(mTextAttributes.getEffectiveFontSize()));
732-
spans.add(new ReactForegroundColorSpan(getCurrentTextColor()));
730+
workingText.setSpan(
731+
new ReactAbsoluteSizeSpan(mTextAttributes.getEffectiveFontSize()),
732+
0,
733+
workingText.length(),
734+
spanFlags);
735+
736+
workingText.setSpan(
737+
new ReactForegroundColorSpan(getCurrentTextColor()), 0, workingText.length(), spanFlags);
733738

734739
int backgroundColor = mReactBackgroundManager.getBackgroundColor();
735740
if (backgroundColor != Color.TRANSPARENT) {
736-
spans.add(new ReactBackgroundColorSpan(backgroundColor));
741+
workingText.setSpan(
742+
new ReactBackgroundColorSpan(backgroundColor), 0, workingText.length(), spanFlags);
737743
}
738744

739745
if ((getPaintFlags() & Paint.STRIKE_THRU_TEXT_FLAG) != 0) {
740-
spans.add(new ReactStrikethroughSpan());
746+
workingText.setSpan(new ReactStrikethroughSpan(), 0, workingText.length(), spanFlags);
741747
}
742748

743749
if ((getPaintFlags() & Paint.UNDERLINE_TEXT_FLAG) != 0) {
744-
spans.add(new ReactUnderlineSpan());
750+
workingText.setSpan(new ReactUnderlineSpan(), 0, workingText.length(), spanFlags);
745751
}
746752

747753
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
748754
float effectiveLetterSpacing = mTextAttributes.getEffectiveLetterSpacing();
749755
if (!Float.isNaN(effectiveLetterSpacing)) {
750-
spans.add(new CustomLetterSpacingSpan(effectiveLetterSpacing));
756+
workingText.setSpan(
757+
new CustomLetterSpacingSpan(effectiveLetterSpacing),
758+
0,
759+
workingText.length(),
760+
spanFlags);
751761
}
752762
}
753-
754-
for (Object span : spans) {
755-
workingText.setSpan(span, 0, workingText.length(), spanFlags);
756-
}
757763
}
758764

759765
private static boolean sameTextForSpan(

0 commit comments

Comments
 (0)
Please sign in to comment.