diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index ddea201e600..cfb6b5031c1 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -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( diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index 1acbd252d97..1509f49963e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -172,12 +172,15 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { public 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); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRoot.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRoot.java index 1c7c0591710..a97220763e4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRoot.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRoot.java @@ -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(); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java index 7689411afd5..bac6a458c82 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java @@ -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);