Permalink
Browse files

On Android, seperate logic to initialize JS from starting the app

Reviewed By: achen1

Differential Revision: D6606265

fbshipit-source-id: d432661b5f8aa2b7600b1140e1617aab852f343e
  • Loading branch information...
axe-fb authored and facebook-github-bot committed Dec 20, 2017
1 parent 19a9c5e commit 4996b9aeb4127892b7579b45927dec14833b8b4d
@@ -1044,7 +1044,7 @@ private void attachRootViewToInstance(
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",
@@ -87,6 +87,7 @@
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,42 +380,69 @@ public void setAppProperties(@Nullable Bundle appProperties) {
UiThreadUtil.assertOnUiThread();
mAppProperties = appProperties;
if (getRootViewTag() != 0) {
runApplication();
invokeJSEntryPoint();
}
}
/**
* 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;
}
/*package */ void invokeJSEntryPoint() {
if (mJSEntryPoint == null) {
defaultJSEntryPoint();
} else {
mJSEntryPoint.run();
}
}
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
if (reactContext == null) {
return;
}
/**
* Set a custom entry point for invoking JS. By default, this is AppRegistry.runApplication
* @param jsEntryPoint
*/
public void setJSEntryPoint(Runnable jsEntryPoint) {
mJSEntryPoint = jsEntryPoint;
}
CatalystInstance catalystInstance = reactContext.getCatalystInstance();
public void invokeDefaultJSEntryPoint(@Nullable Bundle appProperties) {
UiThreadUtil.assertOnUiThread();
if (appProperties != null) {
mAppProperties = appProperties;
}
defaultJSEntryPoint();
}
WritableNativeMap appParams = new WritableNativeMap();
appParams.putDouble("rootTag", getRootViewTag());
@Nullable Bundle appProperties = getAppProperties();
if (appProperties != null) {
appParams.putMap("initialProps", Arguments.fromBundle(appProperties));
}
/**
* 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;
}
mShouldLogContentAppeared = true;
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
if (reactContext == null) {
return;
}
String jsAppModuleName = getJSModuleName();
catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams);
} finally {
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}
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);
}
}
/**

0 comments on commit 4996b9a

Please sign in to comment.