Selaa lähdekoodia

await startApp

Resolve promise when startTabBasedApp and startSingleScreenApp complete.
Guy Carmeli 6 vuotta sitten
vanhempi
commit
bf001063c9

+ 4
- 2
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java Näytä tiedosto

@@ -1,5 +1,7 @@
1 1
 package com.reactnativenavigation.bridge;
2 2
 
3
+import android.support.annotation.Nullable;
4
+
3 5
 import com.facebook.react.bridge.Callback;
4 6
 import com.facebook.react.bridge.Promise;
5 7
 import com.facebook.react.bridge.ReactApplicationContext;
@@ -52,8 +54,8 @@ public class NavigationReactModule extends ReactContextBaseJavaModule {
52 54
     }
53 55
 
54 56
     @ReactMethod
55
-    public void startApp(final ReadableMap params) {
56
-        NavigationCommandsHandler.startApp(BundleConverter.toBundle(params));
57
+    public void startApp(final ReadableMap params, final @Nullable Promise promise) {
58
+        NavigationCommandsHandler.startApp(BundleConverter.toBundle(params), promise);
57 59
     }
58 60
 
59 61
     @ReactMethod

+ 20
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java Näytä tiedosto

@@ -54,6 +54,7 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
54 54
      * Along with that, we should handle commands from the bridge using onNewIntent
55 55
      */
56 56
     static NavigationActivity currentActivity;
57
+    private static Promise startAppPromise;
57 58
 
58 59
     private ActivityParams activityParams;
59 60
     private ModalController modalController;
@@ -123,12 +124,20 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
123 124
         currentActivity = this;
124 125
         IntentDataHandler.onResume(getIntent());
125 126
         getReactGateway().onResumeActivity(this, this);
127
+        resolveStartAppPromiseOnActivityResumed();
126 128
         NavigationApplication.instance.getActivityCallbacks().onActivityResumed(this);
127 129
         EventBus.instance.register(this);
128 130
         IntentDataHandler.onPostResume(getIntent());
129 131
         NavigationApplication.instance.getEventEmitter().sendActivityResumed(getCurrentlyVisibleEventId());
130 132
     }
131 133
 
134
+    private void resolveStartAppPromiseOnActivityResumed() {
135
+        if (startAppPromise != null) {
136
+            startAppPromise.resolve(true);
137
+            startAppPromise = null;
138
+        }
139
+    }
140
+
132 141
     @Override
133 142
     protected void onNewIntent(Intent intent) {
134 143
         super.onNewIntent(intent);
@@ -149,9 +158,16 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
149 158
     @Override
150 159
     protected void onStop() {
151 160
         super.onStop();
161
+        clearStartAppPromise();
152 162
         NavigationApplication.instance.getActivityCallbacks().onActivityStopped(this);
153 163
     }
154 164
 
165
+    private void clearStartAppPromise() {
166
+        if (startAppPromise != null) {
167
+            startAppPromise = null;
168
+        }
169
+    }
170
+
155 171
     @Override
156 172
     protected void onDestroy() {
157 173
         destroyLayouts();
@@ -464,4 +480,8 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
464 480
     public String getCurrentlyVisibleEventId() {
465 481
         return modalController.isShowing() ? modalController.getCurrentlyVisibleEventId() : layout.getCurrentScreen().getNavigatorEventId();
466 482
     }
483
+
484
+    public static void setStartAppPromise(Promise promise) {
485
+        NavigationActivity.startAppPromise = promise;
486
+    }
467 487
 }

+ 2
- 7
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationCommandsHandler.java Näytä tiedosto

@@ -32,18 +32,13 @@ public class NavigationCommandsHandler {
32 32
         return ActivityParamsParser.parse(intent.getBundleExtra(NavigationCommandsHandler.ACTIVITY_PARAMS_BUNDLE));
33 33
     }
34 34
 
35
-    /**
36
-     * start a new activity with CLEAR_TASK | NEW_TASK
37
-     *
38
-     * @param params ActivityParams as bundle
39
-     */
40
-
41
-    public static void startApp(Bundle params) {
35
+    public static void startApp(Bundle params, Promise promise) {
42 36
         Intent intent = new Intent(NavigationApplication.instance, NavigationActivity.class);
43 37
         IntentDataHandler.onStartApp(intent);
44 38
         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
45 39
         intent.putExtra(ACTIVITY_PARAMS_BUNDLE, params);
46 40
         intent.putExtra("animationType", params.getString("animationType"));
41
+        NavigationActivity.setStartAppPromise(promise);
47 42
         NavigationApplication.instance.startActivity(intent);
48 43
     }
49 44
 

+ 4
- 4
src/Navigation.js Näytä tiedosto

@@ -131,12 +131,12 @@ function dismissInAppNotification(params = {}) {
131 131
   return platformSpecific.dismissInAppNotification(params);
132 132
 }
133 133
 
134
-function startTabBasedApp(params) {
135
-  return platformSpecific.startTabBasedApp(params);
134
+async function startTabBasedApp(params) {
135
+  return await platformSpecific.startTabBasedApp(params);
136 136
 }
137 137
 
138
-function startSingleScreenApp(params) {
139
-  return platformSpecific.startSingleScreenApp(params);
138
+async function startSingleScreenApp(params) {
139
+  return await platformSpecific.startSingleScreenApp(params);
140 140
 }
141 141
 
142 142
 function setEventHandler(navigatorEventID, eventHandler) {

+ 4
- 4
src/deprecated/platformSpecificDeprecated.android.js Näytä tiedosto

@@ -10,7 +10,7 @@ const resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSou
10 10
 
11 11
 import * as newPlatformSpecific from './../platformSpecific';
12 12
 
13
-function startSingleScreenApp(params) {
13
+async function startSingleScreenApp(params) {
14 14
   const screen = params.screen;
15 15
   if (!screen.screen) {
16 16
     console.error('startSingleScreenApp(params): screen must include a screen property');
@@ -36,7 +36,7 @@ function startSingleScreenApp(params) {
36 36
   params.overrideBackPress = screen.overrideBackPress;
37 37
   params.animateShow = convertAnimationType(params.animationType);
38 38
 
39
-  newPlatformSpecific.startApp(params);
39
+  return await newPlatformSpecific.startApp(params);
40 40
 }
41 41
 
42 42
 function getOrientation(params) {
@@ -279,7 +279,7 @@ function adaptNavigationParams(screen) {
279 279
   return screen;
280 280
 }
281 281
 
282
-function startTabBasedApp(params) {
282
+async function startTabBasedApp(params) {
283 283
   if (!params.tabs) {
284 284
     console.error('startTabBasedApp(params): params.tabs is required');
285 285
     return;
@@ -317,7 +317,7 @@ function startTabBasedApp(params) {
317 317
   params.sideMenu = convertDrawerParamsToSideMenuParams(params.drawer);
318 318
   params.animateShow = convertAnimationType(params.animationType);
319 319
 
320
-  newPlatformSpecific.startApp(params);
320
+  return await newPlatformSpecific.startApp(params);
321 321
 }
322 322
 
323 323
 function addTabIcon(tab) {

+ 2
- 2
src/platformSpecific.android.js Näytä tiedosto

@@ -5,9 +5,9 @@ import PropRegistry from './PropRegistry';
5 5
 
6 6
 const NativeReactModule = NativeModules.NavigationReactModule;
7 7
 
8
-function startApp(activityParams) {
8
+async function startApp(activityParams) {
9 9
   savePassProps(activityParams);
10
-  NativeReactModule.startApp(activityParams);
10
+  return await NativeReactModule.startApp(activityParams);
11 11
 }
12 12
 
13 13
 function push(screenParams) {