Browse Source

fix push while transitioning (#983)

Ran 7 years ago
parent
commit
ee5af114a5
1 changed files with 53 additions and 20 deletions
  1. 53
    20
      ios/RCCNavigationController.m

+ 53
- 20
ios/RCCNavigationController.m View File

8
 #import "UIViewController+Rotation.h"
8
 #import "UIViewController+Rotation.h"
9
 
9
 
10
 @implementation RCCNavigationController
10
 @implementation RCCNavigationController
11
+{
12
+  BOOL _transitioning;
13
+  NSMutableArray *_queuedViewControllers;
14
+}
11
 
15
 
12
 NSString const *CALLBACK_ASSOCIATED_KEY = @"RCCNavigationController.CALLBACK_ASSOCIATED_KEY";
16
 NSString const *CALLBACK_ASSOCIATED_KEY = @"RCCNavigationController.CALLBACK_ASSOCIATED_KEY";
13
 NSString const *CALLBACK_ASSOCIATED_ID = @"RCCNavigationController.CALLBACK_ASSOCIATED_ID";
17
 NSString const *CALLBACK_ASSOCIATED_ID = @"RCCNavigationController.CALLBACK_ASSOCIATED_ID";
19
 
23
 
20
 - (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge
24
 - (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge
21
 {
25
 {
26
+  _queuedViewControllers = [NSMutableArray new];
27
+  
22
   NSString *component = props[@"component"];
28
   NSString *component = props[@"component"];
23
   if (!component) return nil;
29
   if (!component) return nil;
24
   
30
   
218
     [topViewController setNavBarVisibilityChange:animatedBool];
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
 -(void)onButtonPress:(UIBarButtonItem*)barButtonItem
252
 -(void)onButtonPress:(UIBarButtonItem*)barButtonItem
334
   return [self.topViewController preferredStatusBarStyle];
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
 #pragma mark - UINavigationControllerDelegate
359
 #pragma mark - UINavigationControllerDelegate
339
 
360
 
342
   [viewController setNeedsStatusBarAppearanceUpdate];
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
 @end
379
 @end