Expose SurfaceID as part ReactRootView

Summary:
This diff exposes the surfaceID as part of ReactRootView.

Changelog: [internal]

Reviewed By: JoshuaGross

Differential Revision: D18474014

fbshipit-source-id: 98f651b211d3cc4df88c6b1eb257bc12129eff57
This commit is contained in:
David Vacca
2019-11-15 17:28:12 -08:00
committed by Facebook Github Bot
parent 76f41a0578
commit f0b6f8441b
4 changed files with 24 additions and 4 deletions
@@ -426,6 +426,13 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
mShouldLogContentAppeared = shouldLogContentAppeared;
}
@Nullable
@Override
public String getSurfaceID() {
Bundle appProperties = getAppProperties();
return appProperties != null ? appProperties.getString("surfaceID") : null;
}
private void updateRootLayoutSpecs(final int widthMeasureSpec, final int heightMeasureSpec) {
if (mReactInstanceManager == null) {
FLog.w(
@@ -172,12 +172,15 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
public <T extends View> int addRootView(
final T rootView, final WritableMap initialProps, final @Nullable String initialUITemplate) {
final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
ReactRoot reactRootView = (ReactRoot) rootView;
// TODO T31905686: Combine with startSurface below
ThemedReactContext reactContext =
new ThemedReactContext(mReactApplicationContext, rootView.getContext());
new ThemedReactContext(
mReactApplicationContext, rootView.getContext(), reactRootView.getSurfaceID());
mMountingManager.addRootView(rootTag, rootView);
String moduleName = reactRootView.getJSModuleName();
mReactContextForRootTag.put(rootTag, reactContext);
String moduleName = ((ReactRoot) rootView).getJSModuleName();
if (ENABLE_FABRIC_LOGS) {
FLog.d(TAG, "Starting surface for module: %s and reactTag: %d", moduleName, rootTag);
}
@@ -198,7 +201,7 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
int heightMeasureSpec) {
final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
ThemedReactContext reactContext =
new ThemedReactContext(mReactApplicationContext, rootView.getContext());
new ThemedReactContext(mReactApplicationContext, rootView.getContext(), moduleName);
if (ENABLE_FABRIC_LOGS) {
FLog.d(TAG, "Starting surface for module: %s and reactTag: %d", moduleName, rootTag);
}
@@ -48,4 +48,13 @@ public interface ReactRoot {
/** Sets a flag that determines whether to log that content appeared on next view added. */
void setShouldLogContentAppeared(boolean shouldLogContentAppeared);
/**
* @return a {@link String} that represents the root js application that is being rendered with
* this {@link ReactRoot}
* @deprecated We recommend to not use this method as it is will be replaced in the near future.
*/
@Deprecated
@Nullable
String getSurfaceID();
}
@@ -417,7 +417,8 @@ public class UIManagerModule extends ReactContextBaseJavaModule
final int tag = ReactRootViewTagGenerator.getNextRootViewTag();
final ReactApplicationContext reactApplicationContext = getReactApplicationContext();
final ThemedReactContext themedRootContext =
new ThemedReactContext(reactApplicationContext, rootView.getContext());
new ThemedReactContext(
reactApplicationContext, rootView.getContext(), ((ReactRoot) rootView).getSurfaceID());
mUIImplementation.registerRootView(rootView, tag, themedRootContext);
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);