From 22f81b203fa39878c88f20dd3fcce941c2acc490 Mon Sep 17 00:00:00 2001 From: Andrei Shikov Date: Wed, 18 Aug 2021 12:43:18 -0700 Subject: [PATCH] Clean up Fabric startSurface API used in Venice Summary: Update FabricUIManager methods for `SurfaceHandler` to start usual rendering or prerendering based on presence of the view instead of using two methods with same logic. Changelog: [Internal] Reviewed By: sshic Differential Revision: D30346502 fbshipit-source-id: 297f2b4a16dc7af7c36379252bd73e6dc953ff59 --- .../react/fabric/FabricUIManager.java | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) 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 54750ad386f13e..76e084d9a75920 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 int startSurface( 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(); + + 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); + } - startSurfaceWithId(surfaceHandler, rootTag, false); + 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 void attachRootView(final View rootView, final SurfaceHandler surfaceHand 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(