From 8638f6a735a8842486a44f9f5527faa14d2c2dec Mon Sep 17 00:00:00 2001 From: mangogogos Date: Tue, 19 Jan 2016 14:37:32 -0800 Subject: [PATCH] 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 --- .../main/java/com/facebook/react/ReactActivity.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactActivity.java b/ReactAndroid/src/main/java/com/facebook/react/ReactActivity.java index 064c3b8b3..c9679fafb 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactActivity.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactActivity.java @@ -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); }