Browse Source

getLaunchArgs android

Daniel Zlotin 6 years ago
parent
commit
f9005cc91a

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java View File

276
     public void getCurrentlyVisibleScreenId(Promise promise) {
276
     public void getCurrentlyVisibleScreenId(Promise promise) {
277
         NavigationCommandsHandler.getCurrentlyVisibleScreenId(promise);
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 View File

1
 package com.reactnativenavigation.controllers;
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
 public class NavigationCommandsHandler {
16
 public class NavigationCommandsHandler {
28
 
17
 
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 View File

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

+ 21
- 0
android/app/src/main/java/com/reactnativenavigation/react/LaunchArgs.java View File

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 View File

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

+ 8
- 3
src/deprecated/platformSpecificDeprecated.android.js View File

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