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 a161270395222b..290c3b6048bac2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -213,7 +213,7 @@ public int addRootView( ThemedReactContext reactContext = new ThemedReactContext( mReactApplicationContext, rootView.getContext(), reactRootView.getSurfaceID(), rootTag); - mMountingManager.startSurface(rootTag, rootView, reactContext); + mMountingManager.startSurface(rootTag, reactContext, rootView); String moduleName = reactRootView.getJSModuleName(); if (ENABLE_FABRIC_LOGS) { FLog.d(TAG, "Starting surface for module: %s and reactTag: %d", moduleName, rootTag); @@ -271,7 +271,7 @@ public int startSurface( if (ENABLE_FABRIC_LOGS) { FLog.d(TAG, "Starting surface for module: %s and reactTag: %d", moduleName, rootTag); } - mMountingManager.startSurface(rootTag, rootView, reactContext); + mMountingManager.startSurface(rootTag, reactContext, rootView); // 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 @@ -295,18 +295,14 @@ public int startSurface( return rootTag; } - public void startSurface(final SurfaceHandler surfaceHandler, final @Nullable View rootView) { + public void startSurface( + final SurfaceHandler surfaceHandler, final Context context, final @Nullable View rootView) { final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag(); - if (rootView == null) { - mMountingManager.startSurface(rootTag); - } else { - Context context = rootView.getContext(); - ThemedReactContext reactContext = - new ThemedReactContext( - mReactApplicationContext, context, surfaceHandler.getModuleName(), rootTag); - mMountingManager.startSurface(rootTag, rootView, reactContext); - } + ThemedReactContext reactContext = + new ThemedReactContext( + mReactApplicationContext, context, surfaceHandler.getModuleName(), rootTag); + mMountingManager.startSurface(rootTag, reactContext, rootView); surfaceHandler.setSurfaceId(rootTag); if (surfaceHandler instanceof SurfaceHandlerBinding) { 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 7e00a20defd00e..7c303f38c2ad0b 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 @@ -75,27 +75,21 @@ public MountingManager( mMountItemExecutor = mountItemExecutor; } - /** Starts surface and attaches the root view. */ - @AnyThread - public void startSurface( - final int surfaceId, @NonNull final View rootView, ThemedReactContext themedReactContext) { - SurfaceMountingManager mountingManager = startSurface(surfaceId); - mountingManager.attachRootView(rootView, themedReactContext); - } - /** * Starts surface without attaching the view. All view operations executed against that surface * will be queued until the view is attached. */ @AnyThread - public SurfaceMountingManager startSurface(final int surfaceId) { + public SurfaceMountingManager startSurface( + final int surfaceId, ThemedReactContext reactContext, @Nullable View rootView) { SurfaceMountingManager surfaceMountingManager = new SurfaceMountingManager( surfaceId, mJSResponderHandler, mViewManagerRegistry, mRootViewManager, - mMountItemExecutor); + mMountItemExecutor, + reactContext); // There could technically be a race condition here if addRootView is called twice from // different threads, though this is (probably) extremely unlikely, and likely an error. @@ -111,6 +105,11 @@ public SurfaceMountingManager startSurface(final int surfaceId) { } mMostRecentSurfaceMountingManager = mSurfaceIdToManager.get(surfaceId); + + if (rootView != null) { + surfaceMountingManager.attachRootView(rootView, reactContext); + } + return surfaceMountingManager; } @@ -314,8 +313,8 @@ public void updateProps(int reactTag, @Nullable ReadableMap props) { } /** - * Clears the JS Responder specified by {@link #setJSResponder(int, int, int, boolean)}. After - * this method is called, all the touch events are going to be handled by JS. + * Clears the JS Responder specified by {@link SurfaceMountingManager#setJSResponder}. After this + * method is called, all the touch events are going to be handled by JS. */ @UiThread public void clearJSResponder() { diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java index 737a29559aab5f..8e1fe87bd7d5ea 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java @@ -76,13 +76,15 @@ public SurfaceMountingManager( @NonNull JSResponderHandler jsResponderHandler, @NonNull ViewManagerRegistry viewManagerRegistry, @NonNull RootViewManager rootViewManager, - @NonNull MountItemExecutor mountItemExecutor) { + @NonNull MountItemExecutor mountItemExecutor, + @NonNull ThemedReactContext reactContext) { mSurfaceId = surfaceId; mJSResponderHandler = jsResponderHandler; mViewManagerRegistry = viewManagerRegistry; mRootViewManager = rootViewManager; mMountItemExecutor = mountItemExecutor; + mThemedReactContext = reactContext; } public boolean isStopped() {