Provide a method to easily provide initial props to a ReactAndroid application

Summary:
Adds back support for initial props in ReactAndroid while maintaining the abstraction benefits of having the details of ReactActivity abstracted from the end user's MainActivity. This does remove the need for ReactRootView's two paramater version of the overloaded startReactApplication as far as I can tell but I wasn't sure if anyone might be using that method internally.
Closes https://github.com/facebook/react-native/pull/5384

Reviewed By: svcscm

Differential Revision: D2841602

Pulled By: androidtrunkagent

fb-gh-sync-id: 07e0937bbbdb3ac1585aa252e2fd0f3736690898
This commit is contained in:
mangogogos 2016-01-19 14:37:32 -08:00 committed by facebook-github-bot-7
parent 8ea9a1bc94
commit 8638f6a735
1 changed files with 12 additions and 1 deletions

View File

@ -60,6 +60,17 @@ public abstract class ReactActivity extends Activity implements DefaultHardwareB
return "index.android";
}
/**
* Returns the launchOptions which will be passed to the {@link ReactInstanceManager}
* when the application is started. By default, this will return null and an empty
* object will be passed to your top level component as its initial props.
* If your React Native application requires props set outside of JS, override
* this method to return the Android.os.Bundle of your desired initial props.
*/
protected @Nullable Bundle getLaunchOptions() {
return null;
}
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
@ -128,7 +139,7 @@ public abstract class ReactActivity extends Activity implements DefaultHardwareB
mReactInstanceManager = createReactInstanceManager();
ReactRootView mReactRootView = createRootView();
mReactRootView.startReactApplication(mReactInstanceManager, getMainComponentName());
mReactRootView.startReactApplication(mReactInstanceManager, getMainComponentName(), getLaunchOptions());
setContentView(mReactRootView);
}