Skip to content

Commit

Permalink
Try to call setSurfaceId and setId earlier on ReactRootViews
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JoshuaGross authored and facebook-github-bot committed Jan 28, 2021
1 parent 6b1a899 commit de8aa2c
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -136,7 +137,7 @@ private void addRootView(@NonNull final View rootView) {
// 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() {
Expand All @@ -158,8 +159,18 @@ public void run() {
+ "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);
}
}

/**
Expand Down

0 comments on commit de8aa2c

Please sign in to comment.