mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Prevent initialization of constants for view managers for users with static view config enabled
Summary: This diff prevents the pre-calculation of ViewManager's constants for users with static view config enabled. We still load viewManager classes and create viewManger objects for perf reasons Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D25414068 fbshipit-source-id: a91f6113e35b42625c03d13bd67b63e3f9f75098
This commit is contained in:
committed by
Facebook GitHub Bot
parent
408bcdeedb
commit
9c827f6201
@@ -100,4 +100,7 @@ public class ReactFeatureFlags {
|
||||
|
||||
/** Enables the usage of an experimental optimized iterator for ReadableNativeMaps. */
|
||||
public static boolean enableExperimentalReadableNativeMapIterator = false;
|
||||
|
||||
/** Enables Static ViewConfig in RN Android native code. */
|
||||
public static boolean enableExperimentalStaticViewConfigs = false;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.facebook.react.bridge.UiThreadUtil;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
import com.facebook.react.config.ReactFeatureFlags;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
import com.facebook.react.uimanager.common.ViewUtil;
|
||||
import com.facebook.react.uimanager.debug.NotThreadSafeViewHierarchyUpdateDebugListener;
|
||||
@@ -297,6 +298,15 @@ public class UIManagerModule extends ReactContextBaseJavaModule
|
||||
*/
|
||||
@Deprecated
|
||||
public void preComputeConstantsForViewManager(List<String> viewManagerNames) {
|
||||
// TODO T81145457 - Implement pre-initialization of ViewManagers in Fabric Android
|
||||
if (ReactFeatureFlags.enableExperimentalStaticViewConfigs) {
|
||||
preInitializeViewManagers(viewManagerNames);
|
||||
// When Static view configs are enabled it is not necessary to pre-compute the constants for
|
||||
// viewManagers, although the pre-initialization of viewManager objects is still necessary
|
||||
// for performance reasons.
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, WritableMap> constantsMap = new ArrayMap<>();
|
||||
for (String viewManagerName : viewManagerNames) {
|
||||
WritableMap constants = computeConstantsForViewManager(viewManagerName);
|
||||
@@ -315,6 +325,12 @@ public class UIManagerModule extends ReactContextBaseJavaModule
|
||||
mViewManagerConstantsCache = Collections.unmodifiableMap(constantsMap);
|
||||
}
|
||||
|
||||
private void preInitializeViewManagers(List<String> viewManagerNames) {
|
||||
for (String viewManagerName : viewManagerNames) {
|
||||
mUIImplementation.resolveViewManager(viewManagerName);
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod(isBlockingSynchronousMethod = true)
|
||||
public @Nullable WritableMap getConstantsForViewManager(@Nullable String viewManagerName) {
|
||||
if (mViewManagerConstantsCache != null
|
||||
|
||||
Reference in New Issue
Block a user