Skip to content

Commit

Permalink
Clean up Fabric startSurface API used in Venice
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Andrei Shikov authored and facebook-github-bot committed Aug 18, 2021
1 parent 06e31c7 commit 22f81b2
Showing 1 changed file with 19 additions and 26 deletions.
Expand Up @@ -294,14 +294,28 @@ public <T extends View> 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,
Expand All @@ -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(
Expand Down

0 comments on commit 22f81b2

Please sign in to comment.