Browse Source

await startApp

Resolve promise when startTabBasedApp and startSingleScreenApp complete.
Guy Carmeli 6 years ago
parent
commit
bf001063c9

+ 4
- 2
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java View File

1
 package com.reactnativenavigation.bridge;
1
 package com.reactnativenavigation.bridge;
2
 
2
 
3
+import android.support.annotation.Nullable;
4
+
3
 import com.facebook.react.bridge.Callback;
5
 import com.facebook.react.bridge.Callback;
4
 import com.facebook.react.bridge.Promise;
6
 import com.facebook.react.bridge.Promise;
5
 import com.facebook.react.bridge.ReactApplicationContext;
7
 import com.facebook.react.bridge.ReactApplicationContext;
52
     }
54
     }
53
 
55
 
54
     @ReactMethod
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
     @ReactMethod
61
     @ReactMethod

+ 20
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java View File

54
      * Along with that, we should handle commands from the bridge using onNewIntent
54
      * Along with that, we should handle commands from the bridge using onNewIntent
55
      */
55
      */
56
     static NavigationActivity currentActivity;
56
     static NavigationActivity currentActivity;
57
+    private static Promise startAppPromise;
57
 
58
 
58
     private ActivityParams activityParams;
59
     private ActivityParams activityParams;
59
     private ModalController modalController;
60
     private ModalController modalController;
123
         currentActivity = this;
124
         currentActivity = this;
124
         IntentDataHandler.onResume(getIntent());
125
         IntentDataHandler.onResume(getIntent());
125
         getReactGateway().onResumeActivity(this, this);
126
         getReactGateway().onResumeActivity(this, this);
127
+        resolveStartAppPromiseOnActivityResumed();
126
         NavigationApplication.instance.getActivityCallbacks().onActivityResumed(this);
128
         NavigationApplication.instance.getActivityCallbacks().onActivityResumed(this);
127
         EventBus.instance.register(this);
129
         EventBus.instance.register(this);
128
         IntentDataHandler.onPostResume(getIntent());
130
         IntentDataHandler.onPostResume(getIntent());
129
         NavigationApplication.instance.getEventEmitter().sendActivityResumed(getCurrentlyVisibleEventId());
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
     @Override
141
     @Override
133
     protected void onNewIntent(Intent intent) {
142
     protected void onNewIntent(Intent intent) {
134
         super.onNewIntent(intent);
143
         super.onNewIntent(intent);
149
     @Override
158
     @Override
150
     protected void onStop() {
159
     protected void onStop() {
151
         super.onStop();
160
         super.onStop();
161
+        clearStartAppPromise();
152
         NavigationApplication.instance.getActivityCallbacks().onActivityStopped(this);
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
     @Override
171
     @Override
156
     protected void onDestroy() {
172
     protected void onDestroy() {
157
         destroyLayouts();
173
         destroyLayouts();
464
     public String getCurrentlyVisibleEventId() {
480
     public String getCurrentlyVisibleEventId() {
465
         return modalController.isShowing() ? modalController.getCurrentlyVisibleEventId() : layout.getCurrentScreen().getNavigatorEventId();
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 View File

32
         return ActivityParamsParser.parse(intent.getBundleExtra(NavigationCommandsHandler.ACTIVITY_PARAMS_BUNDLE));
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
         Intent intent = new Intent(NavigationApplication.instance, NavigationActivity.class);
36
         Intent intent = new Intent(NavigationApplication.instance, NavigationActivity.class);
43
         IntentDataHandler.onStartApp(intent);
37
         IntentDataHandler.onStartApp(intent);
44
         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
38
         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
45
         intent.putExtra(ACTIVITY_PARAMS_BUNDLE, params);
39
         intent.putExtra(ACTIVITY_PARAMS_BUNDLE, params);
46
         intent.putExtra("animationType", params.getString("animationType"));
40
         intent.putExtra("animationType", params.getString("animationType"));
41
+        NavigationActivity.setStartAppPromise(promise);
47
         NavigationApplication.instance.startActivity(intent);
42
         NavigationApplication.instance.startActivity(intent);
48
     }
43
     }
49
 
44
 

+ 4
- 4
src/Navigation.js View File

131
   return platformSpecific.dismissInAppNotification(params);
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
 function setEventHandler(navigatorEventID, eventHandler) {
142
 function setEventHandler(navigatorEventID, eventHandler) {

+ 4
- 4
src/deprecated/platformSpecificDeprecated.android.js View File

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

+ 2
- 2
src/platformSpecific.android.js View File

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