diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index 320b3c3fc..217d2c117 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -1044,7 +1044,7 @@ public class ReactInstanceManager { UIManagerModule uiManagerModule = catalystInstance.getNativeModule(UIManagerModule.class); final int rootTag = uiManagerModule.addRootView(rootView); rootView.setRootViewTag(rootTag); - rootView.runApplication(); + rootView.invokeJSEntryPoint(); Systrace.beginAsyncSection( TRACE_TAG_REACT_JAVA_BRIDGE, "pre_rootView.onAttachedToReactInstance", diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index 05cfc8d77..045dab14f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -87,6 +87,7 @@ public class ReactRootView extends SizeMonitoringFrameLayout private boolean mWasMeasured = false; private int mWidthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); private int mHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); + private @Nullable Runnable mJSEntryPoint; public ReactRootView(Context context) { super(context); @@ -379,7 +380,7 @@ public class ReactRootView extends SizeMonitoringFrameLayout UiThreadUtil.assertOnUiThread(); mAppProperties = appProperties; if (getRootViewTag() != 0) { - runApplication(); + invokeJSEntryPoint(); } } @@ -387,36 +388,63 @@ public class ReactRootView extends SizeMonitoringFrameLayout * Calls into JS to start the React application. Can be called multiple times with the * same rootTag, which will re-render the application from the root. */ - /* package */ void runApplication() { - Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ReactRootView.runApplication"); - try { - if (mReactInstanceManager == null || !mIsAttachedToInstance) { - return; - } - - ReactContext reactContext = mReactInstanceManager.getCurrentReactContext(); - if (reactContext == null) { - return; - } - - CatalystInstance catalystInstance = reactContext.getCatalystInstance(); - - WritableNativeMap appParams = new WritableNativeMap(); - appParams.putDouble("rootTag", getRootViewTag()); - @Nullable Bundle appProperties = getAppProperties(); - if (appProperties != null) { - appParams.putMap("initialProps", Arguments.fromBundle(appProperties)); - } - - mShouldLogContentAppeared = true; - - String jsAppModuleName = getJSModuleName(); - catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams); - } finally { - Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); + /*package */ void invokeJSEntryPoint() { + if (mJSEntryPoint == null) { + defaultJSEntryPoint(); + } else { + mJSEntryPoint.run(); } } + /** + * Set a custom entry point for invoking JS. By default, this is AppRegistry.runApplication + * @param jsEntryPoint + */ + public void setJSEntryPoint(Runnable jsEntryPoint) { + mJSEntryPoint = jsEntryPoint; + } + + public void invokeDefaultJSEntryPoint(@Nullable Bundle appProperties) { + UiThreadUtil.assertOnUiThread(); + if (appProperties != null) { + mAppProperties = appProperties; + } + defaultJSEntryPoint(); + } + + /** + * Calls the default entry point into JS which is AppRegistry.runApplication() + */ + private void defaultJSEntryPoint() { + Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ReactRootView.runApplication"); + try { + if (mReactInstanceManager == null || !mIsAttachedToInstance) { + return; + } + + ReactContext reactContext = mReactInstanceManager.getCurrentReactContext(); + if (reactContext == null) { + return; + } + + CatalystInstance catalystInstance = reactContext.getCatalystInstance(); + + WritableNativeMap appParams = new WritableNativeMap(); + appParams.putDouble("rootTag", getRootViewTag()); + @Nullable Bundle appProperties = getAppProperties(); + if (appProperties != null) { + appParams.putMap("initialProps", Arguments.fromBundle(appProperties)); + } + + mShouldLogContentAppeared = true; + + String jsAppModuleName = getJSModuleName(); + catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams); + } finally { + Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); + } + } + /** * Is used by unit test to setup mIsAttachedToWindow flags, that will let this * view to be properly attached to catalyst instance by startReactApplication call