Skip to content

Commit 64eeb81

Browse files
NickGerlemankelset
authored andcommittedApr 19, 2023
Minimize EditText Spans 6/9: letterSpacing (#36548)
Summary: Pull Request resolved: #36548 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 lets us set `letterSpacing` on the EditText instead of using our custom span. Changelog: [Android][Fixed] - Minimize EditText Spans 6/N: letterSpacing Reviewed By: rshest Differential Revision: D44240777 fbshipit-source-id: 9bd10c3261257037d8cacf37971011aaa94d1a77
1 parent 44a96ac commit 64eeb81

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
 

‎ReactAndroid/src/main/java/com/facebook/react/views/text/CustomLetterSpacingSpan.java

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public void updateMeasureState(TextPaint paint) {
3737
apply(paint);
3838
}
3939

40+
public float getSpacing() {
41+
return mLetterSpacing;
42+
}
43+
4044
private void apply(TextPaint paint) {
4145
if (!Float.isNaN(mLetterSpacing)) {
4246
paint.setLetterSpacing(mLetterSpacing);

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,18 @@ public boolean test(ReactUnderlineSpan span) {
691691
return (getPaintFlags() & Paint.UNDERLINE_TEXT_FLAG) != 0;
692692
}
693693
});
694+
695+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
696+
stripSpansOfKind(
697+
sb,
698+
CustomLetterSpacingSpan.class,
699+
new SpanPredicate<CustomLetterSpacingSpan>() {
700+
@Override
701+
public boolean test(CustomLetterSpacingSpan span) {
702+
return span.getSpacing() == mTextAttributes.getEffectiveLetterSpacing();
703+
}
704+
});
705+
}
694706
}
695707

696708
private <T> void stripSpansOfKind(
@@ -732,6 +744,13 @@ private void restoreStyleEquivalentSpans(SpannableStringBuilder workingText) {
732744
spans.add(new ReactUnderlineSpan());
733745
}
734746

747+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
748+
float effectiveLetterSpacing = mTextAttributes.getEffectiveLetterSpacing();
749+
if (!Float.isNaN(effectiveLetterSpacing)) {
750+
spans.add(new CustomLetterSpacingSpan(effectiveLetterSpacing));
751+
}
752+
}
753+
735754
for (Object span : spans) {
736755
workingText.setSpan(span, 0, workingText.length(), spanFlags);
737756
}
@@ -1083,7 +1102,9 @@ protected void applyTextAttributes() {
10831102

10841103
float effectiveLetterSpacing = mTextAttributes.getEffectiveLetterSpacing();
10851104
if (!Float.isNaN(effectiveLetterSpacing)) {
1086-
setLetterSpacing(effectiveLetterSpacing);
1105+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
1106+
setLetterSpacing(effectiveLetterSpacing);
1107+
}
10871108
}
10881109
}
10891110

0 commit comments

Comments
 (0)
Please sign in to comment.