mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Minimize EditText Spans 6/9: letterSpacing (#36548)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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]( https://github.com/facebook/react-native/issues/35936#issuecomment-1411437789) 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
This commit is contained in:
committed by
Lorenzo Sciandra
parent
44a96acc20
commit
64eeb819b9
@@ -37,6 +37,10 @@ public class CustomLetterSpacingSpan extends MetricAffectingSpan implements Reac
|
||||
apply(paint);
|
||||
}
|
||||
|
||||
public float getSpacing() {
|
||||
return mLetterSpacing;
|
||||
}
|
||||
|
||||
private void apply(TextPaint paint) {
|
||||
if (!Float.isNaN(mLetterSpacing)) {
|
||||
paint.setLetterSpacing(mLetterSpacing);
|
||||
|
||||
@@ -691,6 +691,18 @@ public class ReactEditText extends AppCompatEditText
|
||||
return (getPaintFlags() & Paint.UNDERLINE_TEXT_FLAG) != 0;
|
||||
}
|
||||
});
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
stripSpansOfKind(
|
||||
sb,
|
||||
CustomLetterSpacingSpan.class,
|
||||
new SpanPredicate<CustomLetterSpacingSpan>() {
|
||||
@Override
|
||||
public boolean test(CustomLetterSpacingSpan span) {
|
||||
return span.getSpacing() == mTextAttributes.getEffectiveLetterSpacing();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private <T> void stripSpansOfKind(
|
||||
@@ -732,6 +744,13 @@ public class ReactEditText extends AppCompatEditText
|
||||
spans.add(new ReactUnderlineSpan());
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
float effectiveLetterSpacing = mTextAttributes.getEffectiveLetterSpacing();
|
||||
if (!Float.isNaN(effectiveLetterSpacing)) {
|
||||
spans.add(new CustomLetterSpacingSpan(effectiveLetterSpacing));
|
||||
}
|
||||
}
|
||||
|
||||
for (Object span : spans) {
|
||||
workingText.setSpan(span, 0, workingText.length(), spanFlags);
|
||||
}
|
||||
@@ -1083,7 +1102,9 @@ public class ReactEditText extends AppCompatEditText
|
||||
|
||||
float effectiveLetterSpacing = mTextAttributes.getEffectiveLetterSpacing();
|
||||
if (!Float.isNaN(effectiveLetterSpacing)) {
|
||||
setLetterSpacing(effectiveLetterSpacing);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
setLetterSpacing(effectiveLetterSpacing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user