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 54750ad386f..76e084d9a75 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -294,14 +294,28 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { return rootTag; } - public void startSurface(final SurfaceHandler surfaceHandler) { - int rootTag = ReactRootViewTagGenerator.getNextRootViewTag(); - mMountingManager.startSurface(rootTag); + public void startSurface(final SurfaceHandler surfaceHandler, final @Nullable View rootView) { + final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag(); - startSurfaceWithId(surfaceHandler, rootTag, false); + 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); + } + + surfaceHandler.setSurfaceId(rootTag); + if (surfaceHandler instanceof SurfaceHandlerBinding) { + mBinding.registerSurface((SurfaceHandlerBinding) surfaceHandler); + } + surfaceHandler.setMountable(rootView != null); + surfaceHandler.start(); } - public void attachRootView(final View rootView, final SurfaceHandler surfaceHandler) { + public void attachRootView(final SurfaceHandler surfaceHandler, final View rootView) { ThemedReactContext reactContext = new ThemedReactContext( mReactApplicationContext, @@ -313,27 +327,6 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { surfaceHandler.setMountable(true); } - public void startSurfaceWithView(final View rootView, final SurfaceHandler surfaceHandler) { - final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag(); - - Context context = rootView.getContext(); - ThemedReactContext reactContext = - new ThemedReactContext( - mReactApplicationContext, context, surfaceHandler.getModuleName(), rootTag); - mMountingManager.startSurface(rootTag, rootView, reactContext); - - startSurfaceWithId(surfaceHandler, rootTag, true); - } - - private void startSurfaceWithId(SurfaceHandler surfaceHandler, int rootTag, boolean isMountable) { - surfaceHandler.setSurfaceId(rootTag); - if (surfaceHandler instanceof SurfaceHandlerBinding) { - mBinding.registerSurface((SurfaceHandlerBinding) surfaceHandler); - } - surfaceHandler.setMountable(isMountable); - surfaceHandler.start(); - } - public void stopSurface(final SurfaceHandler surfaceHandler) { if (!surfaceHandler.isRunning()) { ReactSoftExceptionLogger.logSoftException(