From 8c9c8ba5adb59f7f891a5307a0bce7200dd3ac7d Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Fri, 24 Mar 2023 05:24:09 -0700 Subject: [PATCH] Minimize EditText Spans 4/9: ReactForegroundColorSpan (#36545) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36545 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 adds ReactForegroundColorSpan to the list of spans eligible to be stripped. Changelog: [Android][Fixed] - Minimize Spans 4/N: ReactForegroundColorSpan Reviewed By: javache Differential Revision: D44240780 fbshipit-source-id: d86939cc2d7ed9116a4167026c7d48928fc51757 --- .../react/views/textinput/ReactEditText.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index aba83f2b289e8a..7b9e84a97b7526 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -52,6 +52,7 @@ import com.facebook.react.views.text.CustomStyleSpan; import com.facebook.react.views.text.ReactAbsoluteSizeSpan; import com.facebook.react.views.text.ReactBackgroundColorSpan; +import com.facebook.react.views.text.ReactForegroundColorSpan; import com.facebook.react.views.text.ReactSpan; import com.facebook.react.views.text.ReactTextUpdate; import com.facebook.react.views.text.ReactTypefaceUtils; @@ -692,6 +693,16 @@ public boolean test(ReactBackgroundColorSpan span) { return span.getBackgroundColor() == mReactBackgroundManager.getBackgroundColor(); } }); + + stripSpansOfKind( + sb, + ReactForegroundColorSpan.class, + new SpanPredicate() { + @Override + public boolean test(ReactForegroundColorSpan span) { + return span.getForegroundColor() == getCurrentTextColor(); + } + }); } private void stripSpansOfKind( @@ -718,6 +729,7 @@ private void restoreStyleEquivalentSpans(SpannableStringBuilder workingText) { List spans = new ArrayList<>(); spans.add(new ReactAbsoluteSizeSpan(mTextAttributes.getEffectiveFontSize())); + spans.add(new ReactForegroundColorSpan(getCurrentTextColor())); int backgroundColor = mReactBackgroundManager.getBackgroundColor(); if (backgroundColor != Color.TRANSPARENT) {