ソースを参照

fix push while transitioning (#983)

Ran 7 年 前
コミット
ee5af114a5
共有1 個のファイルを変更した53 個の追加20 個の削除を含む
  1. 53
    20
      ios/RCCNavigationController.m

+ 53
- 20
ios/RCCNavigationController.m ファイルの表示

@@ -8,6 +8,10 @@
8 8
 #import "UIViewController+Rotation.h"
9 9
 
10 10
 @implementation RCCNavigationController
11
+{
12
+  BOOL _transitioning;
13
+  NSMutableArray *_queuedViewControllers;
14
+}
11 15
 
12 16
 NSString const *CALLBACK_ASSOCIATED_KEY = @"RCCNavigationController.CALLBACK_ASSOCIATED_KEY";
13 17
 NSString const *CALLBACK_ASSOCIATED_ID = @"RCCNavigationController.CALLBACK_ASSOCIATED_ID";
@@ -19,6 +23,8 @@ NSString const *CALLBACK_ASSOCIATED_ID = @"RCCNavigationController.CALLBACK_ASSO
19 23
 
20 24
 - (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge
21 25
 {
26
+  _queuedViewControllers = [NSMutableArray new];
27
+  
22 28
   NSString *component = props[@"component"];
23 29
   if (!component) return nil;
24 30
   
@@ -218,29 +224,29 @@ NSString const *CALLBACK_ASSOCIATED_ID = @"RCCNavigationController.CALLBACK_ASSO
218 224
     [topViewController setNavBarVisibilityChange:animatedBool];
219 225
     
220 226
   }
227
+  
228
+  // setStyle
229
+  if ([performAction isEqualToString:@"setStyle"])
230
+  {
231
+    
232
+    NSDictionary *navigatorStyle = actionParams;
221 233
     
222
-    // setStyle
223
-    if ([performAction isEqualToString:@"setStyle"])
234
+    // merge the navigatorStyle of our parent
235
+    if ([self.topViewController isKindOfClass:[RCCViewController class]])
224 236
     {
225
-        
226
-        NSDictionary *navigatorStyle = actionParams;
227
-        
228
-        // merge the navigatorStyle of our parent
229
-        if ([self.topViewController isKindOfClass:[RCCViewController class]])
230
-        {
231
-            RCCViewController *parent = (RCCViewController*)self.topViewController;
232
-            NSMutableDictionary *mergedStyle = [NSMutableDictionary dictionaryWithDictionary:parent.navigatorStyle];
233
-            
234
-            // there are a few styles that we don't want to remember from our parent (they should be local)
235
-            [mergedStyle setValuesForKeysWithDictionary:navigatorStyle];
236
-            navigatorStyle = mergedStyle;
237
-            
238
-            parent.navigatorStyle = navigatorStyle;
239
-            
240
-            [parent setStyleOnInit];
241
-            [parent updateStyle];
242
-        }
237
+      RCCViewController *parent = (RCCViewController*)self.topViewController;
238
+      NSMutableDictionary *mergedStyle = [NSMutableDictionary dictionaryWithDictionary:parent.navigatorStyle];
239
+      
240
+      // there are a few styles that we don't want to remember from our parent (they should be local)
241
+      [mergedStyle setValuesForKeysWithDictionary:navigatorStyle];
242
+      navigatorStyle = mergedStyle;
243
+      
244
+      parent.navigatorStyle = navigatorStyle;
245
+      
246
+      [parent setStyleOnInit];
247
+      [parent updateStyle];
243 248
     }
249
+  }
244 250
 }
245 251
 
246 252
 -(void)onButtonPress:(UIBarButtonItem*)barButtonItem
@@ -334,6 +340,21 @@ NSString const *CALLBACK_ASSOCIATED_ID = @"RCCNavigationController.CALLBACK_ASSO
334 340
   return [self.topViewController preferredStatusBarStyle];
335 341
 }
336 342
 
343
+- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
344
+{
345
+  if(_transitioning)
346
+  {
347
+    NSDictionary *pushDetails =@{ @"viewController": viewController, @"animated": @(animated) };
348
+    [_queuedViewControllers addObject:pushDetails];
349
+    
350
+    return;
351
+  }
352
+  
353
+  _transitioning = YES;
354
+  
355
+  [super pushViewController:viewController animated:animated];
356
+}
357
+
337 358
 
338 359
 #pragma mark - UINavigationControllerDelegate
339 360
 
@@ -342,5 +363,17 @@ NSString const *CALLBACK_ASSOCIATED_ID = @"RCCNavigationController.CALLBACK_ASSO
342 363
   [viewController setNeedsStatusBarAppearanceUpdate];
343 364
 }
344 365
 
366
+- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
367
+{
368
+  dispatch_async(dispatch_get_main_queue(), ^{
369
+    _transitioning = NO;
370
+    if ([_queuedViewControllers count] > 0) {
371
+      NSDictionary *toPushDetails = [_queuedViewControllers firstObject];
372
+      [_queuedViewControllers removeObjectAtIndex:0];
373
+      [self pushViewController:toPushDetails[@"viewController"] animated:[toPushDetails[@"animated"] boolValue]];
374
+    }
375
+  });
376
+}
377
+
345 378
 
346 379
 @end