From b3defc887239d5edbcb8559ae3a021cf2775be95 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Tue, 29 Dec 2020 15:06:15 -0800 Subject: [PATCH] Refactor preComputeConstantsForViewManager to avoid loading UIManagerModule in Fabric Summary: This method refactors the preComputeConstantsForViewManager to avoid loading UIManagerModule when using Fabric + Static View configs changelog: [internal] internal Reviewed By: shergin Differential Revision: D25468182 fbshipit-source-id: e95b0e7d013e832792fb77fc0b6e5705d7f04868 --- .../com/facebook/react/bridge/UIManager.java | 12 ++++++++++++ .../facebook/react/fabric/FabricUIManager.java | 7 +++++++ .../react/fabric/mounting/MountingManager.java | 4 ++++ .../react/uimanager/UIManagerModule.java | 16 ++++++---------- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/UIManager.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/UIManager.java index 74af261f5b4..f07ec720b98 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/UIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/UIManager.java @@ -14,6 +14,7 @@ import androidx.annotation.AnyThread; import androidx.annotation.Nullable; import androidx.annotation.UiThread; import com.facebook.infer.annotation.ThreadConfined; +import java.util.List; public interface UIManager extends JSIModule, PerformanceCounter { @@ -129,4 +130,15 @@ public interface UIManager extends JSIModule, PerformanceCounter { @Deprecated @Nullable String resolveCustomDirectEventName(@Nullable String eventName); + + /** + * Helper method to pre-initialize view managers. When using Native ViewConfigs this method will + * also pre-compute the constants for a view manager. The purpose is to ensure that we don't block + * for getting the constants for view managers during initial rendering of a surface. + * + * @deprecated this method will be removed in the future + * @param viewManagerNames {@link List } names of ViewManagers + */ + @Deprecated + void preInitializeViewManagers(List viewManagerNames); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index 89487503194..82f743be085 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -229,6 +229,13 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { return rootTag; } + @Override + public void preInitializeViewManagers(List viewManagerNames) { + for (String viewManagerName : viewManagerNames) { + mMountingManager.initializeViewManager(viewManagerName); + } + } + @Override @AnyThread @ThreadConfined(ANY) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java index be91c29c23e..2ea54f35e42 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountingManager.java @@ -782,6 +782,10 @@ public class MountingManager { return viewState == null ? null : viewState.mEventEmitter; } + public void initializeViewManager(String componentName) { + mViewManagerRegistry.get(componentName); + } + /** * This class holds view state for react tags. Objects of this class are stored into the {@link * #mTagToViewState}, and they should be updated in the same thread. diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java index c54cf11316a..51f84ebc940 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java @@ -294,14 +294,16 @@ public class UIManagerModule extends ReactContextBaseJavaModule * Helper method to pre-compute the constants for a view manager. This method ensures that we * don't block for getting the constants for view managers during TTI * - * @deprecated this method will not be available in FabricUIManager class. + * @deprecated this method will be removed in the future * @param viewManagerNames {@link List} names of ViewManagers */ @Deprecated - public void preComputeConstantsForViewManager(List viewManagerNames) { - // TODO T81145457 - Implement pre-initialization of ViewManagers in Fabric Android + @Override + public void preInitializeViewManagers(List viewManagerNames) { if (ReactFeatureFlags.enableExperimentalStaticViewConfigs) { - preInitializeViewManagers(viewManagerNames); + for (String viewManagerName : viewManagerNames) { + mUIImplementation.resolveViewManager(viewManagerName); + } // 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. @@ -326,12 +328,6 @@ public class UIManagerModule extends ReactContextBaseJavaModule mViewManagerConstantsCache = Collections.unmodifiableMap(constantsMap); } - private void preInitializeViewManagers(List viewManagerNames) { - for (String viewManagerName : viewManagerNames) { - mUIImplementation.resolveViewManager(viewManagerName); - } - } - @ReactMethod(isBlockingSynchronousMethod = true) public @Nullable WritableMap getConstantsForViewManager(@Nullable String viewManagerName) { if (mViewManagerConstantsCache != null