Skip to content

Commit 3dcd5c8

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Partial 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 the most common cases, when it is sufficient to set `android:textSize`. In simple cases, it causes typing into the TextInput to no longer hang. This does not 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 could potentially do further work to reduce the number of spans emitted in these scenarios, but this may be fighting a losing battle against the platform. Changelog: [Android][Fixed] - Partial Mitigation for Samsung TextInput Hangs (Paper) Reviewed By: cortinico Differential Revision: D42721684 fbshipit-source-id: 1b6935014c8055c3bd547c7ba5294bb9975479c2
1 parent a8166bd commit 3dcd5c8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,10 @@ public void maybeSetText(ReactTextUpdate reactTextUpdate) {
585585
new SpannableStringBuilder(reactTextUpdate.getText());
586586

587587
manageSpans(spannableStringBuilder, reactTextUpdate.mContainsMultipleFragments);
588+
589+
// Mitigation for https://github.com/facebook/react-native/issues/35936 (S318090)
590+
stripAbsoluteSizeSpans(spannableStringBuilder);
591+
588592
mContainsImages = reactTextUpdate.containsImages();
589593

590594
// When we update text, we trigger onChangeText code that will
@@ -658,6 +662,31 @@ private void manageSpans(
658662
}
659663
}
660664

665+
private void stripAbsoluteSizeSpans(SpannableStringBuilder sb) {
666+
// We have already set a font size on the EditText itself. We can safely remove sizing spans
667+
// which are the same as the set font size, and not otherwise overlapped.
668+
final int effectiveFontSize = mTextAttributes.getEffectiveFontSize();
669+
ReactAbsoluteSizeSpan[] spans = sb.getSpans(0, sb.length(), ReactAbsoluteSizeSpan.class);
670+
671+
outer:
672+
for (ReactAbsoluteSizeSpan span : spans) {
673+
if (span.getSize() != effectiveFontSize) {
674+
continue;
675+
}
676+
677+
ReactAbsoluteSizeSpan[] overlappingSpans =
678+
sb.getSpans(sb.getSpanStart(span), sb.getSpanEnd(sb), ReactAbsoluteSizeSpan.class);
679+
680+
for (ReactAbsoluteSizeSpan overlappingSpan : overlappingSpans) {
681+
if (span.getSize() != effectiveFontSize) {
682+
continue outer;
683+
}
684+
}
685+
686+
sb.removeSpan(span);
687+
}
688+
}
689+
661690
private static boolean sameTextForSpan(
662691
final Editable oldText,
663692
final SpannableStringBuilder newText,

0 commit comments

Comments
 (0)