From 5cba7c0ce71c6ec0aac33bd712928a7ae858654f Mon Sep 17 00:00:00 2001 From: Andrei Shikov Date: Mon, 12 Apr 2021 13:16:01 -0700 Subject: [PATCH] Add a way to prerender the surface Summary: Changelog: [Internal] Links APIs in Fabric and Venice to create a surface without a view and mount it separately when surface is started the usual way. Reviewed By: mdvacca Differential Revision: D27339365 fbshipit-source-id: d1b674ce856957465eb6f3a5d7f26eb0ab625353 --- .../react/fabric/FabricUIManager.java | 28 +++++++++++++++++-- .../fabric/jni/SurfaceHandlerBinding.cpp | 1 - 2 files changed, 26 insertions(+), 3 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 7383420ee79..aa01b18d593 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -255,7 +255,26 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { return rootTag; } - public void startSurface(final View rootView, SurfaceHandler surfaceHandler) { + public void startSurface(final SurfaceHandler surfaceHandler) { + int rootTag = ReactRootViewTagGenerator.getNextRootViewTag(); + mMountingManager.startSurface(rootTag); + + startSurfaceWithId(surfaceHandler, rootTag, false); + } + + public void attachRootView(final View rootView, final SurfaceHandler surfaceHandler) { + ThemedReactContext reactContext = + new ThemedReactContext( + mReactApplicationContext, + rootView.getContext(), + surfaceHandler.getModuleName(), + surfaceHandler.getSurfaceId()); + mMountingManager.attachRootView(surfaceHandler.getSurfaceId(), rootView, reactContext); + + surfaceHandler.setMountable(true); + } + + public void startSurfaceWithView(final View rootView, final SurfaceHandler surfaceHandler) { final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag(); Context context = rootView.getContext(); @@ -264,14 +283,19 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { 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(SurfaceHandler surfaceHandler) { + public void stopSurface(final SurfaceHandler surfaceHandler) { if (!surfaceHandler.isRunning()) { ReactSoftException.logSoftException( FabricUIManager.TAG, diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/SurfaceHandlerBinding.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/SurfaceHandlerBinding.cpp index 8e4e90a13a7..96affa4b750 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/SurfaceHandlerBinding.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/SurfaceHandlerBinding.cpp @@ -23,7 +23,6 @@ void SurfaceHandlerBinding::setDisplayMode(jint mode) { void SurfaceHandlerBinding::start() { std::unique_lock lock(lifecycleMutex_); - surfaceHandler_.setDisplayMode(DisplayMode::Visible); if (surfaceHandler_.getStatus() != SurfaceHandler::Status::Running) { surfaceHandler_.start(); }