From de8aa2c6b985d5ec3f49f9176de2daebbf17f0c4 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Thu, 28 Jan 2021 14:01:07 -0800 Subject: [PATCH] Try to call setSurfaceId and setId earlier on ReactRootViews Summary: We assume that startSurface is always called off the UI thread; see if we can synchronously call setId and setSurfaceId, and in general, call setSurfaceId sooner. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D26053050 fbshipit-source-id: a657584502bb0018e9591fe610eac0fc9fab2ca9 --- .../fabric/mounting/SurfaceMountingManager.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java index 5c3686e7787..0231061f4a2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java @@ -29,6 +29,7 @@ import com.facebook.react.common.build.ReactBuildConfig; import com.facebook.react.fabric.events.EventEmitterWrapper; import com.facebook.react.touch.JSResponderHandler; import com.facebook.react.uimanager.IllegalViewOperationException; +import com.facebook.react.uimanager.ReactRoot; import com.facebook.react.uimanager.ReactStylesDiffMap; import com.facebook.react.uimanager.RootView; import com.facebook.react.uimanager.RootViewManager; @@ -136,7 +137,7 @@ public class SurfaceMountingManager { // Since this is called from the constructor, we know the surface cannot have stopped yet. mTagToViewState.put(mSurfaceId, new ViewState(mSurfaceId, rootView, mRootViewManager, true)); - UiThreadUtil.runOnUiThread( + Runnable runnable = new Runnable() { @Override public void run() { @@ -158,8 +159,18 @@ public class SurfaceMountingManager { + "explicitly overwrite the id field to View.NO_ID before calling addRootView."); } rootView.setId(mSurfaceId); + + if (rootView instanceof ReactRoot) { + ((ReactRoot) rootView).setRootViewTag(mSurfaceId); + } } - }); + }; + + if (UiThreadUtil.isOnUiThread()) { + runnable.run(); + } else { + UiThreadUtil.runOnUiThread(runnable); + } } /**