Browse Source

async await fix for ios

yogevbd 6 years ago
parent
commit
fd4e7091c0

+ 7
- 6
ios/RCCManagerModule.m View File

143
 -(void)dismissAllModalPresenters:(NSMutableArray*)allPresentedViewControllers resolver:(RCTPromiseResolveBlock)resolve
143
 -(void)dismissAllModalPresenters:(NSMutableArray*)allPresentedViewControllers resolver:(RCTPromiseResolveBlock)resolve
144
 {
144
 {
145
     UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
145
     UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
146
-
146
+    
147
     if (allPresentedViewControllers.count > 0)
147
     if (allPresentedViewControllers.count > 0)
148
     {
148
     {
149
         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^
149
         dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^
205
 #pragma mark - RCT exported methods
205
 #pragma mark - RCT exported methods
206
 
206
 
207
 RCT_EXPORT_METHOD(
207
 RCT_EXPORT_METHOD(
208
-                  setRootController:(NSDictionary*)layout animationType:(NSString*)animationType globalProps:(NSDictionary*)globalProps)
208
+                  setRootController:(NSDictionary*)layout animationType:(NSString*)animationType globalProps:(NSDictionary*)globalProps resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
209
 {
209
 {
210
     if ([[RCCManager sharedInstance] getBridge].loading) {
210
     if ([[RCCManager sharedInstance] getBridge].loading) {
211
-        [self deferSetRootControllerWhileBridgeLoading:layout animationType:animationType globalProps:globalProps];
211
+        [self deferSetRootControllerWhileBridgeLoading:layout animationType:animationType globalProps:globalProps resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject];
212
         return;
212
         return;
213
     }
213
     }
214
     
214
     
215
     dispatch_async(dispatch_get_main_queue(), ^{
215
     dispatch_async(dispatch_get_main_queue(), ^{
216
         [self performSetRootController:layout animationType:animationType globalProps:globalProps];
216
         [self performSetRootController:layout animationType:animationType globalProps:globalProps];
217
+        resolve(nil);
217
     });
218
     });
218
 }
219
 }
219
 
220
 
220
 /**
221
 /**
221
  * on RN31 there's a timing issue, we must wait for the bridge to finish loading
222
  * on RN31 there's a timing issue, we must wait for the bridge to finish loading
222
  */
223
  */
223
--(void)deferSetRootControllerWhileBridgeLoading:(NSDictionary*)layout animationType:(NSString*)animationType globalProps:(NSDictionary*)globalProps
224
+-(void)deferSetRootControllerWhileBridgeLoading:(NSDictionary*)layout animationType:(NSString*)animationType globalProps:(NSDictionary*)globalProps resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject
224
 {
225
 {
225
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0001 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
226
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0001 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
226
-        [self setRootController:layout animationType:animationType globalProps:globalProps];
227
+        [self setRootController:layout animationType:animationType globalProps:globalProps resolver:resolve rejecter:reject];
227
     });
228
     });
228
 }
229
 }
229
 
230
 
421
     }
422
     }
422
     else
423
     else
423
     {
424
     {
424
-      resolve(nil);
425
+        resolve(nil);
425
     }
426
     }
426
 }
427
 }
427
 
428
 

+ 2
- 3
src/deprecated/controllers/index.js View File

121
     registerController: function (appKey, getControllerFunc) {
121
     registerController: function (appKey, getControllerFunc) {
122
       _controllerRegistry[appKey] = getControllerFunc();
122
       _controllerRegistry[appKey] = getControllerFunc();
123
     },
123
     },
124
-    setRootController: function (appKey, animationType = 'none', passProps = {}) {
124
+    setRootController: async function (appKey, animationType = 'none', passProps = {}) {
125
       var controller = _controllerRegistry[appKey];
125
       var controller = _controllerRegistry[appKey];
126
       if (controller === undefined) return;
126
       if (controller === undefined) return;
127
       var layout = controller.render();
127
       var layout = controller.render();
128
       _validateDrawerProps(layout);
128
       _validateDrawerProps(layout);
129
       _processProperties(_.get(layout, 'props.appStyle', {}));
129
       _processProperties(_.get(layout, 'props.appStyle', {}));
130
-      RCCManager.setRootController(layout, animationType, passProps);
130
+      return await RCCManager.setRootController(layout, animationType, passProps);
131
     }
131
     }
132
   },
132
   },
133
 
133
 
328
 };
328
 };
329
 
329
 
330
 module.exports = Controllers;
330
 module.exports = Controllers;
331
-

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

14
 
14
 
15
 import PropRegistry from '../PropRegistry';
15
 import PropRegistry from '../PropRegistry';
16
 
16
 
17
-function startTabBasedApp(params) {
17
+async function startTabBasedApp(params) {
18
   if (!params.tabs) {
18
   if (!params.tabs) {
19
     console.error('startTabBasedApp(params): params.tabs is required');
19
     console.error('startTabBasedApp(params): params.tabs is required');
20
     return;
20
     return;
119
   _.set(params, 'passProps.timestamp', Date.now());
119
   _.set(params, 'passProps.timestamp', Date.now());
120
 
120
 
121
   ControllerRegistry.registerController(controllerID, () => Controller);
121
   ControllerRegistry.registerController(controllerID, () => Controller);
122
-  ControllerRegistry.setRootController(controllerID, params.animationType, params.passProps || {});
122
+  return await ControllerRegistry.setRootController(controllerID, params.animationType, params.passProps || {});
123
 }
123
 }
124
 
124
 
125
-function startSingleScreenApp(params) {
125
+async function startSingleScreenApp(params) {
126
   if (!params.screen) {
126
   if (!params.screen) {
127
     console.error('startSingleScreenApp(params): params.screen is required');
127
     console.error('startSingleScreenApp(params): params.screen is required');
128
     return;
128
     return;
199
   savePassProps(params);
199
   savePassProps(params);
200
 
200
 
201
   ControllerRegistry.registerController(controllerID, () => Controller);
201
   ControllerRegistry.registerController(controllerID, () => Controller);
202
-  ControllerRegistry.setRootController(controllerID, params.animationType, params.passProps || {});
202
+  return await ControllerRegistry.setRootController(controllerID, params.animationType, params.passProps || {});
203
 }
203
 }
204
 
204
 
205
 function _mergeScreenSpecificSettings(screenID, screenInstanceID, params) {
205
 function _mergeScreenSpecificSettings(screenID, screenInstanceID, params) {