瀏覽代碼

getLaunchArgs android

Daniel Zlotin 6 年之前
父節點
當前提交
f9005cc91a

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java 查看文件

@@ -276,4 +276,9 @@ public class NavigationReactModule extends ReactContextBaseJavaModule {
276 276
     public void getCurrentlyVisibleScreenId(Promise promise) {
277 277
         NavigationCommandsHandler.getCurrentlyVisibleScreenId(promise);
278 278
     }
279
+
280
+    @ReactMethod
281
+    public void getLaunchArgs(Promise promise) {
282
+        NavigationCommandsHandler.getLaunchArgs(promise);
283
+    }
279 284
 }

+ 17
- 23
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationCommandsHandler.java 查看文件

@@ -1,28 +1,17 @@
1 1
 package com.reactnativenavigation.controllers;
2 2
 
3
-import android.content.Intent;
4
-import android.os.Bundle;
5
-
6
-import com.facebook.react.bridge.Arguments;
7
-import com.facebook.react.bridge.Callback;
8
-import com.facebook.react.bridge.Promise;
9
-import com.facebook.react.bridge.WritableMap;
10
-import com.reactnativenavigation.NavigationApplication;
11
-import com.reactnativenavigation.params.ActivityParams;
12
-import com.reactnativenavigation.params.ContextualMenuParams;
13
-import com.reactnativenavigation.params.FabParams;
14
-import com.reactnativenavigation.params.LightBoxParams;
15
-import com.reactnativenavigation.params.ScreenParams;
16
-import com.reactnativenavigation.params.SlidingOverlayParams;
17
-import com.reactnativenavigation.params.SnackbarParams;
18
-import com.reactnativenavigation.params.TitleBarButtonParams;
19
-import com.reactnativenavigation.params.TitleBarLeftButtonParams;
20
-import com.reactnativenavigation.params.parsers.ActivityParamsParser;
21
-import com.reactnativenavigation.params.parsers.ScreenParamsParser;
22
-import com.reactnativenavigation.utils.OrientationHelper;
23
-import com.reactnativenavigation.views.SideMenu.Side;
24
-
25
-import java.util.List;
3
+import android.content.*;
4
+import android.os.*;
5
+
6
+import com.facebook.react.bridge.*;
7
+import com.reactnativenavigation.*;
8
+import com.reactnativenavigation.params.*;
9
+import com.reactnativenavigation.params.parsers.*;
10
+import com.reactnativenavigation.react.*;
11
+import com.reactnativenavigation.utils.*;
12
+import com.reactnativenavigation.views.SideMenu.*;
13
+
14
+import java.util.*;
26 15
 
27 16
 public class NavigationCommandsHandler {
28 17
 
@@ -557,4 +546,9 @@ public class NavigationCommandsHandler {
557 546
             }
558 547
         });
559 548
     }
549
+
550
+    public static void getLaunchArgs(Promise promise) {
551
+        Bundle bundle = LaunchArgs.instance.get();
552
+        promise.resolve(bundle);
553
+    }
560 554
 }

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/controllers/SplashActivity.java 查看文件

@@ -10,7 +10,7 @@ import android.support.v7.app.AppCompatActivity;
10 10
 import android.view.View;
11 11
 
12 12
 import com.reactnativenavigation.NavigationApplication;
13
-import com.reactnativenavigation.react.ReactDevPermission;
13
+import com.reactnativenavigation.react.*;
14 14
 import com.reactnativenavigation.utils.CompatUtils;
15 15
 
16 16
 public abstract class SplashActivity extends AppCompatActivity {
@@ -30,6 +30,7 @@ public abstract class SplashActivity extends AppCompatActivity {
30 30
     @Override
31 31
     protected void onCreate(@Nullable Bundle savedInstanceState) {
32 32
         super.onCreate(savedInstanceState);
33
+        LaunchArgs.instance.set(getIntent());
33 34
         setSplashLayout();
34 35
         IntentDataHandler.saveIntentData(getIntent());
35 36
     }

+ 21
- 0
android/app/src/main/java/com/reactnativenavigation/react/LaunchArgs.java 查看文件

@@ -0,0 +1,21 @@
1
+package com.reactnativenavigation.react;
2
+
3
+import android.content.*;
4
+import android.os.*;
5
+
6
+public enum LaunchArgs {
7
+    instance;
8
+
9
+    private static final Bundle EMPTY = new Bundle();
10
+    private Bundle launchArgs;
11
+
12
+    public void set(Intent intent) {
13
+        if (intent != null && intent.getExtras() != null && launchArgs != null) {
14
+            this.launchArgs = intent.getExtras();
15
+        }
16
+    }
17
+
18
+    public Bundle get() {
19
+        return this.launchArgs == null ? EMPTY : this.launchArgs;
20
+    }
21
+}

+ 7
- 2
src/Navigation.js 查看文件

@@ -28,7 +28,7 @@ function _registerComponentNoRedux(screenID, generator) {
28 28
     if (!InternalComponent) {
29 29
       console.error(`Navigation: ${screenID} registration result is 'undefined'`);
30 30
     }
31
-    
31
+
32 32
     return class extends Screen {
33 33
       static navigatorStyle = InternalComponent.navigatorStyle || {};
34 34
       static navigatorButtons = InternalComponent.navigatorButtons || {};
@@ -182,6 +182,10 @@ function getCurrentlyVisibleScreenId() {
182 182
   return platformSpecific.getCurrentlyVisibleScreenId();
183 183
 }
184 184
 
185
+async function getLaunchArgs() {
186
+  return await platformSpecific.getLaunchArgs();
187
+}
188
+
185 189
 export default {
186 190
   getRegisteredScreen,
187 191
   getCurrentlyVisibleScreenId,
@@ -200,5 +204,6 @@ export default {
200 204
   clearEventHandler: clearEventHandler,
201 205
   handleDeepLink: handleDeepLink,
202 206
   isAppLaunched: isAppLaunched,
203
-  isRootLaunched: isRootLaunched
207
+  isRootLaunched: isRootLaunched,
208
+  getLaunchArgs
204 209
 };

+ 8
- 3
src/deprecated/platformSpecificDeprecated.android.js 查看文件

@@ -237,7 +237,7 @@ function convertStyleParams(originalStyleObject) {
237 237
   if (ret.topBarReactViewInitialProps) {
238 238
     const passPropsKey = _.uniqueId('customNavBarComponent');
239 239
     PropRegistry.save(passPropsKey, ret.topBarReactViewInitialProps);
240
-    ret.topBarReactViewInitialProps = {passPropsKey};  
240
+    ret.topBarReactViewInitialProps = {passPropsKey};
241 241
   }
242 242
   return ret;
243 243
 }
@@ -267,7 +267,7 @@ function convertDrawerParamsToSideMenuParams(drawerParams) {
267 267
       } else {
268 268
         result[key].fixedWidth = drawer[key].fixedWidth;
269 269
       }
270
-      
270
+
271 271
     } else {
272 272
       result[key] = null;
273 273
     }
@@ -778,6 +778,10 @@ async function getCurrentlyVisibleScreenId() {
778 778
   return await newPlatformSpecific.getCurrentlyVisibleScreenId();
779 779
 }
780 780
 
781
+async function getLaunchArgs() {
782
+  return await NativeReactModule.getLaunchArgs();
783
+}
784
+
781 785
 export default {
782 786
   startTabBasedApp,
783 787
   startSingleScreenApp,
@@ -810,5 +814,6 @@ export default {
810 814
   dismissContextualMenu,
811 815
   isAppLaunched,
812 816
   isRootLaunched,
813
-  getCurrentlyVisibleScreenId
817
+  getCurrentlyVisibleScreenId,
818
+  getLaunchArgs
814 819
 };