From 5fbebb4852d2ef8eaa05bc49fc41fd3772816baa Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Wed, 29 May 2024 13:31:36 -0700 Subject: [PATCH] Cleanup ReactFeatureFlags.enableTextSpannableCache (#44706) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44706 We didn't ship this, and asking around, I don't think mdvacca was looking at this actively (though is on PTO right now). Changelog: [Internal] Reviewed By: rozele Differential Revision: D57913491 fbshipit-source-id: 86afd5a6bb5e7ce6be540f2295aa407134a6d81c --- .../ReactAndroid/api/ReactAndroid.api | 1 - .../react/config/ReactFeatureFlags.java | 3 -- .../react/views/text/TextLayoutManager.java | 31 ++----------------- 3 files changed, 3 insertions(+), 32 deletions(-) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 6cf82dcbf16..9ba54837f74 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -1961,7 +1961,6 @@ public class com/facebook/react/config/ReactFeatureFlags { public static field enableFabricRenderer Z public static field enableFabricRendererExclusively Z public static field enableRemoveDeleteTreeInstruction Z - public static field enableTextSpannableCache Z public static field enableViewRecycling Z public static field excludeYogaFromRawProps Z public static field rejectTurboModulePromiseOnNativeError Z diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java index f823ae02405..c08e2bc9f92 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java @@ -80,9 +80,6 @@ public class ReactFeatureFlags { public static boolean dispatchPointerEvents = false; - /** Feature Flag to enable a cache of Spannable objects used by TextLayoutManager */ - public static boolean enableTextSpannableCache = false; - /** * Feature Flag to enable View Recycling. When enabled, individual ViewManagers must still opt-in. */ diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java index 2b1928d8c41..2921f84140d 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.java @@ -7,8 +7,6 @@ package com.facebook.react.views.text; -import static com.facebook.react.config.ReactFeatureFlags.enableTextSpannableCache; - import android.content.Context; import android.graphics.Color; import android.os.Build; @@ -21,7 +19,6 @@ import android.text.StaticLayout; import android.text.TextDirectionHeuristics; import android.text.TextPaint; import android.util.LayoutDirection; -import android.util.LruCache; import android.view.Gravity; import android.view.View; import androidx.annotation.NonNull; @@ -33,7 +30,6 @@ import com.facebook.react.bridge.WritableArray; import com.facebook.react.common.ReactConstants; import com.facebook.react.common.build.ReactBuildConfig; import com.facebook.react.common.mapbuffer.MapBuffer; -import com.facebook.react.common.mapbuffer.ReadableMapBuffer; import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.ReactAccessibilityDelegate.AccessibilityRole; import com.facebook.react.uimanager.ReactAccessibilityDelegate.Role; @@ -93,23 +89,15 @@ public class TextLayoutManager { // The bug is that unicode emoticons aren't measured properly which causes text to be clipped. private static final TextPaint sTextPaintInstance = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); - // Specifies the amount of spannable that are stored into the {@link sSpannableCache}. - private static final short spannableCacheSize = 10000; - private static final String INLINE_VIEW_PLACEHOLDER = "0"; private static final boolean DEFAULT_INCLUDE_FONT_PADDING = true; private static final boolean DEFAULT_ADJUST_FONT_SIZE_TO_FIT = false; - private static final Object sCacheLock = new Object(); - private static final ConcurrentHashMap sTagToSpannableCache = new ConcurrentHashMap<>(); - private static final LruCache sSpannableCache = - new LruCache<>(spannableCacheSize); - public static void setCachedSpannableForTag(int reactTag, @NonNull Spannable sp) { if (ENABLE_MEASURE_LOGGING) { FLog.e(TAG, "Set cached spannable for tag[" + reactTag + "]: " + sp.toString()); @@ -314,22 +302,9 @@ public class TextLayoutManager { Integer cacheId = attributedString.getInt(AS_KEY_CACHE_ID); text = sTagToSpannableCache.get(cacheId); } else { - if (enableTextSpannableCache && attributedString instanceof ReadableMapBuffer) { - ReadableMapBuffer mapBuffer = (ReadableMapBuffer) attributedString; - synchronized (sCacheLock) { - text = sSpannableCache.get(mapBuffer); - if (text == null) { - text = - createSpannableFromAttributedString( - context, attributedString, reactTextViewManagerCallback); - sSpannableCache.put(mapBuffer, text); - } - } - } else { - text = - createSpannableFromAttributedString( - context, attributedString, reactTextViewManagerCallback); - } + text = + createSpannableFromAttributedString( + context, attributedString, reactTextViewManagerCallback); } return text;