diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index 007480cd423b0c..b6172aee234cba 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -56,10 +56,21 @@ */ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView { + /** + * Listener interface for react root view events + */ + public interface ReactRootViewEventListener { + /** + * Called when the react context is attached to a ReactRootView. + */ + void onAttachedToReactInstance(ReactRootView rootView); + } + private @Nullable ReactInstanceManager mReactInstanceManager; private @Nullable String mJSModuleName; private @Nullable Bundle mLaunchOptions; private @Nullable CustomGlobalLayoutListener mCustomGlobalLayoutListener; + private @Nullable ReactRootViewEventListener mRootViewEventListener; private int mRootViewTag; private boolean mWasMeasured = false; private boolean mIsAttachedToInstance = false; @@ -224,6 +235,16 @@ public void unmountReactApplication() { } } + public void onAttachedToReactInstance() { + if (mRootViewEventListener != null) { + mRootViewEventListener.onAttachedToReactInstance(this); + } + } + + public void setEventListener(ReactRootViewEventListener eventListener) { + mRootViewEventListener = eventListener; + } + /* package */ String getJSModuleName() { return Assertions.assertNotNull(mJSModuleName); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java b/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java index 2a396cb09f2055..a8956a2ebd05c6 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java @@ -810,6 +810,7 @@ private void attachMeasuredRootViewToInstance( appParams.putDouble("rootTag", rootTag); appParams.putMap("initialProps", initialProps); catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams); + rootView.onAttachedToReactInstance(); Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); }