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
This commit is contained in:
Joshua Gross
2021-01-22 19:29:00 -08:00
committed by Facebook GitHub Bot
parent 505f9fc749
commit e7783ff9ad
4 changed files with 16 additions and 4 deletions
@@ -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
<T extends View> int addRootView(
final T rootView, WritableMap initialProps, @Nullable String initialUITemplate);
@@ -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 <T extends View> 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
@@ -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(
@@ -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.
*
* <p>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.
*
* <p>Note that this must be called after getWidth()/getHeight() actually return something. See
* CatalystApplicationFragment as an example.
*