diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index 14863e498018c1..624cc9cc5594d4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -585,6 +585,10 @@ public void maybeSetText(ReactTextUpdate reactTextUpdate) { new SpannableStringBuilder(reactTextUpdate.getText()); manageSpans(spannableStringBuilder, reactTextUpdate.mContainsMultipleFragments); + + // Mitigation for https://github.com/facebook/react-native/issues/35936 (S318090) + stripAbsoluteSizeSpans(spannableStringBuilder); + mContainsImages = reactTextUpdate.containsImages(); // When we update text, we trigger onChangeText code that will @@ -658,6 +662,31 @@ private void manageSpans( } } + private void stripAbsoluteSizeSpans(SpannableStringBuilder sb) { + // We have already set a font size on the EditText itself. We can safely remove sizing spans + // which are the same as the set font size, and not otherwise overlapped. + final int effectiveFontSize = mTextAttributes.getEffectiveFontSize(); + ReactAbsoluteSizeSpan[] spans = sb.getSpans(0, sb.length(), ReactAbsoluteSizeSpan.class); + + outer: + for (ReactAbsoluteSizeSpan span : spans) { + if (span.getSize() != effectiveFontSize) { + continue; + } + + ReactAbsoluteSizeSpan[] overlappingSpans = + sb.getSpans(sb.getSpanStart(span), sb.getSpanEnd(sb), ReactAbsoluteSizeSpan.class); + + for (ReactAbsoluteSizeSpan overlappingSpan : overlappingSpans) { + if (span.getSize() != effectiveFontSize) { + continue outer; + } + } + + sb.removeSpan(span); + } + } + private static boolean sameTextForSpan( final Editable oldText, final SpannableStringBuilder newText,