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
This commit is contained in:
Andrei Shikov
2021-04-12 13:17:52 -07:00
committed by Facebook GitHub Bot
parent d65b5895ce
commit 5cba7c0ce7
2 changed files with 26 additions and 3 deletions
@@ -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,
@@ -23,7 +23,6 @@ void SurfaceHandlerBinding::setDisplayMode(jint mode) {
void SurfaceHandlerBinding::start() {
std::unique_lock<better::shared_mutex> lock(lifecycleMutex_);
surfaceHandler_.setDisplayMode(DisplayMode::Visible);
if (surfaceHandler_.getStatus() != SurfaceHandler::Status::Running) {
surfaceHandler_.start();
}