From e7783ff9ad8d59927ddda99ee21d8e5b63e73f5e Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Fri, 22 Jan 2021 19:29:00 -0800 Subject: [PATCH] Rename addRootView -> startSurface in Fabric, and deprecate existing `addRootView` sites Summary: Deprecate addRootView, use startSurface consistently in Fabric. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D26021147 fbshipit-source-id: e23b9294695609f766e382917ae1874fc8a1b27d --- .../java/com/facebook/react/bridge/UIManager.java | 3 ++- .../com/facebook/react/fabric/FabricUIManager.java | 11 +++++++++-- .../react/fabric/mounting/MountingManager.java | 2 +- .../com/facebook/react/uimanager/UIManagerModule.java | 4 ++++ 4 files changed, 16 insertions(+), 4 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 ad837bf04ea..56a237f9f12 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/UIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/UIManager.java @@ -18,9 +18,10 @@ import java.util.List; public interface UIManager extends JSIModule, PerformanceCounter { - /** Registers a new root view. */ + /** Registers a new root view. @Deprecated call startSurface instead */ @UiThread @ThreadConfined(UI) + @Deprecated int addRootView( final T rootView, WritableMap initialProps, @Nullable String initialUITemplate); 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 cdeed3160ed..51be066ce2f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -68,6 +68,7 @@ import com.facebook.react.fabric.mounting.mountitems.PreAllocateViewMountItem; import com.facebook.react.fabric.mounting.mountitems.SendAccessibilityEvent; import com.facebook.react.modules.core.ReactChoreographer; import com.facebook.react.modules.i18nmanager.I18nUtil; +import com.facebook.react.uimanager.IllegalViewOperationException; import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.ReactRoot; import com.facebook.react.uimanager.ReactRootViewTagGenerator; @@ -174,15 +175,21 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { @Override @UiThread @ThreadConfined(UI) + @Deprecated public int addRootView( final T rootView, final WritableMap initialProps, final @Nullable String initialUITemplate) { + ReactSoftException.logSoftException( + TAG, + new IllegalViewOperationException( + "Do not call addRootView in Fabric; it is unsupported. Call startSurface instead.")); + final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag(); ReactRoot reactRootView = (ReactRoot) rootView; ThemedReactContext reactContext = new ThemedReactContext( mReactApplicationContext, rootView.getContext(), reactRootView.getSurfaceID()); - mMountingManager.addRootView(rootTag, rootView, reactContext); + mMountingManager.startSurface(rootTag, rootView, reactContext); String moduleName = reactRootView.getJSModuleName(); if (ENABLE_FABRIC_LOGS) { FLog.d(TAG, "Starting surface for module: %s and reactTag: %d", moduleName, rootTag); @@ -217,7 +224,7 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { if (ENABLE_FABRIC_LOGS) { FLog.d(TAG, "Starting surface for module: %s and reactTag: %d", moduleName, rootTag); } - mMountingManager.addRootView(rootTag, rootView, reactContext); + mMountingManager.startSurface(rootTag, rootView, reactContext); // If startSurface is executed in the UIThread then, it uses the ViewportOffset from the View, // Otherwise Fabric relies on calling {@link Binding#setConstraints} method to update the 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 774a357be78..94c1c5ecf14 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 @@ -107,7 +107,7 @@ public class MountingManager { * @param rootView */ @AnyThread - public void addRootView( + public void startSurface( final int surfaceId, @NonNull final View rootView, ThemedReactContext themedReactContext) { SurfaceMountingManager surfaceMountingManager = new SurfaceMountingManager( 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 fa24d964f93..324885a494e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java @@ -436,6 +436,10 @@ public class UIManagerModule extends ReactContextBaseJavaModule * Registers a new root view. JS can use the returned tag with manageChildren to add/remove * children to this view. * + *

Calling addRootView through UIManagerModule calls addRootView in the non-Fabric renderer, + * always. This is deprecated in favor of calling startSurface in Fabric, which must be done + * directly through the FabricUIManager. + * *

Note that this must be called after getWidth()/getHeight() actually return something. See * CatalystApplicationFragment as an example. *