Skip to content

Commit 5791cf1

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
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 0869ea2 commit 5791cf1

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

packages/react-native/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);

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,18 @@ public boolean test(ReactUnderlineSpan span) {
726726
return (getPaintFlags() & Paint.UNDERLINE_TEXT_FLAG) != 0;
727727
}
728728
});
729+
730+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
731+
stripSpansOfKind(
732+
sb,
733+
CustomLetterSpacingSpan.class,
734+
new SpanPredicate<CustomLetterSpacingSpan>() {
735+
@Override
736+
public boolean test(CustomLetterSpacingSpan span) {
737+
return span.getSpacing() == mTextAttributes.getEffectiveLetterSpacing();
738+
}
739+
});
740+
}
729741
}
730742

731743
private <T> void stripSpansOfKind(
@@ -767,6 +779,13 @@ private void restoreStyleEquivalentSpans(SpannableStringBuilder workingText) {
767779
spans.add(new ReactUnderlineSpan());
768780
}
769781

782+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
783+
float effectiveLetterSpacing = mTextAttributes.getEffectiveLetterSpacing();
784+
if (!Float.isNaN(effectiveLetterSpacing)) {
785+
spans.add(new CustomLetterSpacingSpan(effectiveLetterSpacing));
786+
}
787+
}
788+
770789
for (Object span : spans) {
771790
workingText.setSpan(span, 0, workingText.length(), spanFlags);
772791
}
@@ -1124,7 +1143,9 @@ protected void applyTextAttributes() {
11241143

11251144
float effectiveLetterSpacing = mTextAttributes.getEffectiveLetterSpacing();
11261145
if (!Float.isNaN(effectiveLetterSpacing)) {
1127-
setLetterSpacing(effectiveLetterSpacing);
1146+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
1147+
setLetterSpacing(effectiveLetterSpacing);
1148+
}
11281149
}
11291150
}
11301151

0 commit comments

Comments
 (0)