Skip to content

Commit b71c1f0

Browse files
NickGerlemandiegolmello
authored andcommitted
Mitigation for Samsung TextInput Hangs (facebook#35967)
Summary: Pull Request resolved: facebook#35967 In facebook#35936 we observed that the presence of AbsoluteSizeSpan may lead to hangs when using the Grammarly keyboard on Samsung. This mitigation makes it so that we do not emit this span in any case where it is sufficient to rely on already set EditText textSize. In simple cases, tested on two devices, it causes typing into the TextInput to no longer hang. This does not fully resolve the issue for TextInputs which meaningfully use layout-effecting spans (or at least font size), such as non-uniform text size within the input. We instead just try to reduce to minimum AbsoluteSizeSpan possible. Testing the first commit was able to resolve hangs in some simpler inputs tested, by me and cortinico. Changelog: [Android][Fixed] - Mitigation for Samsung TextInput Hangs Reviewed By: cortinico Differential Revision: D42721684 fbshipit-source-id: e0388dfb4617f0217bc1d0b71752c733e10261dd
1 parent 986c3c8 commit b71c1f0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ public void maybeSetText(ReactTextUpdate reactTextUpdate) {
549549
new SpannableStringBuilder(reactTextUpdate.getText());
550550

551551
manageSpans(spannableStringBuilder, reactTextUpdate.mContainsMultipleFragments);
552+
553+
// Mitigation for https://github.com/facebook/react-native/issues/35936 (S318090)
554+
stripAbsoluteSizeSpans(spannableStringBuilder);
555+
552556
mContainsImages = reactTextUpdate.containsImages();
553557

554558
// When we update text, we trigger onChangeText code that will
@@ -622,6 +626,27 @@ private void manageSpans(
622626
}
623627
}
624628

629+
private void stripAbsoluteSizeSpans(SpannableStringBuilder sb) {
630+
// We have already set a font size on the EditText itself. We can safely remove sizing spans
631+
// which are the same as the set font size, and not otherwise overlapped.
632+
final int effectiveFontSize = mTextAttributes.getEffectiveFontSize();
633+
ReactAbsoluteSizeSpan[] spans = sb.getSpans(0, sb.length(), ReactAbsoluteSizeSpan.class);
634+
635+
outerLoop:
636+
for (ReactAbsoluteSizeSpan span : spans) {
637+
ReactAbsoluteSizeSpan[] overlappingSpans =
638+
sb.getSpans(sb.getSpanStart(span), sb.getSpanEnd(span), ReactAbsoluteSizeSpan.class);
639+
640+
for (ReactAbsoluteSizeSpan overlappingSpan : overlappingSpans) {
641+
if (span.getSize() != effectiveFontSize) {
642+
continue outerLoop;
643+
}
644+
}
645+
646+
sb.removeSpan(span);
647+
}
648+
}
649+
625650
private static boolean sameTextForSpan(
626651
final Editable oldText,
627652
final SpannableStringBuilder newText,

0 commit comments

Comments
 (0)