react-native-navigation的迁移库

RCCNavigationController.m 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. #import "RCCNavigationController.h"
  2. #import "RCCViewController.h"
  3. #import "RCCManager.h"
  4. #import <React/RCTEventDispatcher.h>
  5. #import <React/RCTUIManager.h>
  6. #if __has_include(<React/RCTUIManagerUtils.h>)
  7. #import <React/RCTUIManagerUtils.h>
  8. #endif
  9. #import <React/RCTConvert.h>
  10. #import <React/RCTRootView.h>
  11. #import <objc/runtime.h>
  12. #import "RCCTitleViewHelper.h"
  13. #import "RCCCustomBarButtonItem.h"
  14. #import "UIViewController+Rotation.h"
  15. #import "RCTHelpers.h"
  16. #import "RCTConvert+UIBarButtonSystemItem.h"
  17. @implementation RCCNavigationController
  18. {
  19. BOOL _transitioning;
  20. NSMutableArray *_queuedViewControllers;
  21. }
  22. NSString const *CALLBACK_ASSOCIATED_KEY = @"RCCNavigationController.CALLBACK_ASSOCIATED_KEY";
  23. NSString const *CALLBACK_ASSOCIATED_ID = @"RCCNavigationController.CALLBACK_ASSOCIATED_ID";
  24. -(UIInterfaceOrientationMask)supportedInterfaceOrientations {
  25. return [self supportedControllerOrientations];
  26. }
  27. - (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary*)globalProps bridge:(RCTBridge *)bridge
  28. {
  29. _queuedViewControllers = [NSMutableArray new];
  30. NSString *component = props[@"component"];
  31. if (!component) return nil;
  32. NSDictionary *passProps = props[@"passProps"];
  33. NSDictionary *navigatorStyle = props[@"style"];
  34. RCCViewController *viewController = [[RCCViewController alloc] initWithComponent:component passProps:passProps navigatorStyle:navigatorStyle globalProps:globalProps bridge:bridge];
  35. if (!viewController) return nil;
  36. viewController.controllerId = passProps[@"screenInstanceID"];
  37. NSArray *leftButtons = props[@"leftButtons"];
  38. if (leftButtons)
  39. {
  40. [self setButtons:leftButtons viewController:viewController side:@"left" animated:NO];
  41. }
  42. NSArray *rightButtons = props[@"rightButtons"];
  43. if (rightButtons)
  44. {
  45. [self setButtons:rightButtons viewController:viewController side:@"right" animated:NO];
  46. }
  47. self = [super initWithRootViewController:viewController];
  48. if (!self) return nil;
  49. self.delegate = self;
  50. self.navigationBar.translucent = NO; // default
  51. [self processTitleView:viewController
  52. props:props
  53. style:navigatorStyle];
  54. [self setRotation:props];
  55. NSArray* components = props[@"components"];
  56. if (components.count) {
  57. for (NSDictionary* component in components) {
  58. NSMutableDictionary *mutableParams = [[NSMutableDictionary alloc] initWithDictionary:@{@"animated": @(0), @"component": component[@"screen"]}];
  59. [mutableParams addEntriesFromDictionary:component];
  60. [self performAction:@"push" actionParams:mutableParams bridge:bridge];
  61. }
  62. }
  63. return self;
  64. }
  65. - (void)performAction:(NSString*)performAction actionParams:(NSDictionary*)actionParams bridge:(RCTBridge *)bridge
  66. {
  67. BOOL animated = actionParams[@"animated"] ? [actionParams[@"animated"] boolValue] : YES;
  68. // push
  69. if ([performAction isEqualToString:@"push"])
  70. {
  71. NSString *component = actionParams[@"component"];
  72. if (!component) return;
  73. NSMutableDictionary *passProps = [actionParams[@"passProps"] mutableCopy];
  74. passProps[GLOBAL_SCREEN_ACTION_COMMAND_TYPE] = COMMAND_TYPE_PUSH;
  75. passProps[GLOBAL_SCREEN_ACTION_TIMESTAMP] = actionParams[GLOBAL_SCREEN_ACTION_TIMESTAMP];
  76. NSDictionary *navigatorStyle = actionParams[@"style"] ? actionParams[@"style"] : actionParams[@"navigatorStyle"];
  77. NSNumber *keepStyleAcrossPush = [[RCCManager sharedInstance] getAppStyle][@"keepStyleAcrossPush"];
  78. BOOL keepStyleAcrossPushBool = keepStyleAcrossPush ? [keepStyleAcrossPush boolValue] : YES;
  79. if (keepStyleAcrossPushBool) {
  80. if ([self.topViewController isKindOfClass:[RCCViewController class]])
  81. {
  82. RCCViewController *parent = (RCCViewController*)self.topViewController;
  83. NSMutableDictionary *mergedStyle = [NSMutableDictionary dictionaryWithDictionary:parent.navigatorStyle];
  84. // there are a few styles that we don't want to remember from our parent (they should be local)
  85. [mergedStyle removeObjectForKey:@"navBarHidden"];
  86. [mergedStyle removeObjectForKey:@"statusBarHidden"];
  87. [mergedStyle removeObjectForKey:@"navBarHideOnScroll"];
  88. [mergedStyle removeObjectForKey:@"drawUnderNavBar"];
  89. [mergedStyle removeObjectForKey:@"drawUnderTabBar"];
  90. [mergedStyle removeObjectForKey:@"statusBarBlur"];
  91. [mergedStyle removeObjectForKey:@"navBarBlur"];
  92. [mergedStyle removeObjectForKey:@"navBarTranslucent"];
  93. [mergedStyle removeObjectForKey:@"statusBarHideWithNavBar"];
  94. [mergedStyle removeObjectForKey:@"autoAdjustScrollViewInsets"];
  95. [mergedStyle removeObjectForKey:@"statusBarTextColorSchemeSingleScreen"];
  96. [mergedStyle removeObjectForKey:@"disabledBackGesture"];
  97. [mergedStyle removeObjectForKey:@"disabledSimultaneousGesture"];
  98. [mergedStyle removeObjectForKey:@"navBarCustomView"];
  99. [mergedStyle removeObjectForKey:@"navBarComponentAlignment"];
  100. [mergedStyle addEntriesFromDictionary:navigatorStyle];
  101. navigatorStyle = mergedStyle;
  102. }
  103. }
  104. RCCViewController *viewController = [[RCCViewController alloc] initWithComponent:component passProps:passProps navigatorStyle:navigatorStyle globalProps:nil bridge:bridge];
  105. viewController.controllerId = passProps[@"screenInstanceID"];
  106. [self processTitleView:viewController
  107. props:actionParams
  108. style:navigatorStyle];
  109. NSString *backButtonTitle = actionParams[@"backButtonTitle"];
  110. if (!backButtonTitle) {
  111. NSNumber *hideBackButtonTitle = [[RCCManager sharedInstance] getAppStyle][@"hideBackButtonTitle"];
  112. BOOL hideBackButtonTitleBool = hideBackButtonTitle ? [hideBackButtonTitle boolValue] : NO;
  113. backButtonTitle = hideBackButtonTitleBool ? @"" : backButtonTitle;
  114. }
  115. if (backButtonTitle)
  116. {
  117. UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:backButtonTitle
  118. style:UIBarButtonItemStylePlain
  119. target:nil
  120. action:nil];
  121. self.topViewController.navigationItem.backBarButtonItem = backItem;
  122. }
  123. else
  124. {
  125. self.topViewController.navigationItem.backBarButtonItem = nil;
  126. }
  127. NSNumber *backButtonHidden = actionParams[@"backButtonHidden"];
  128. BOOL backButtonHiddenBool = backButtonHidden ? [backButtonHidden boolValue] : NO;
  129. if (backButtonHiddenBool)
  130. {
  131. viewController.navigationItem.hidesBackButton = YES;
  132. }
  133. NSArray *leftButtons = actionParams[@"leftButtons"];
  134. if (leftButtons)
  135. {
  136. [self setButtons:leftButtons viewController:viewController side:@"left" animated:NO];
  137. }
  138. NSArray *rightButtons = actionParams[@"rightButtons"];
  139. if (rightButtons)
  140. {
  141. [self setButtons:rightButtons viewController:viewController side:@"right" animated:NO];
  142. }
  143. NSArray *previewActions = actionParams[@"previewActions"];
  144. NSString *previewViewID = actionParams[@"previewViewID"];
  145. if (previewViewID) {
  146. if ([self.topViewController isKindOfClass:[RCCViewController class]])
  147. {
  148. RCCViewController *topViewController = ((RCCViewController*)self.topViewController);
  149. topViewController.previewController = nil;
  150. [topViewController.navigationController unregisterForPreviewingWithContext:topViewController.previewContext];
  151. viewController.previewActions = previewActions;
  152. viewController.previewCommit = actionParams[@"previewCommit"] ? [actionParams[@"previewCommit"] boolValue] : YES;
  153. NSNumber *previewHeight = actionParams[@"previewHeight"];
  154. if (previewHeight) {
  155. viewController.preferredContentSize = CGSizeMake(viewController.view.frame.size.width, [previewHeight floatValue]);
  156. }
  157. if (topViewController.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)
  158. {
  159. dispatch_async(RCTGetUIManagerQueue(), ^{
  160. [bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
  161. UIView *view = viewRegistry[previewViewID];
  162. topViewController.previewView = view;
  163. topViewController.previewContext = [topViewController registerForPreviewingWithDelegate:(id)topViewController sourceView:view];
  164. }];
  165. });
  166. topViewController.previewController = viewController;
  167. }
  168. return;
  169. }
  170. }
  171. NSString *animationType = actionParams[@"animationType"];
  172. if ([animationType isEqualToString:@"fade"])
  173. {
  174. CATransition *transition = [CATransition animation];
  175. transition.duration = 0.25;
  176. transition.type = kCATransitionFade;
  177. [self.view.layer addAnimation:transition forKey:kCATransition];
  178. [self pushViewController:viewController animated:NO];
  179. }
  180. else
  181. {
  182. [self pushViewController:viewController animated:animated];
  183. }
  184. return;
  185. }
  186. // pop
  187. if ([performAction isEqualToString:@"pop"])
  188. {
  189. NSString *animationType = actionParams[@"animationType"];
  190. if ([animationType isEqualToString:@"fade"])
  191. {
  192. CATransition *transition = [CATransition animation];
  193. transition.duration = 0.25;
  194. transition.type = kCATransitionFade;
  195. [self.view.layer addAnimation:transition forKey:kCATransition];
  196. [self popViewControllerAnimated:NO];
  197. }
  198. else
  199. {
  200. [self popViewControllerAnimated:animated];
  201. }
  202. return;
  203. }
  204. // popToRoot
  205. if ([performAction isEqualToString:@"popToRoot"])
  206. {
  207. NSString *animationType = actionParams[@"animationType"];
  208. if ([animationType isEqualToString:@"fade"])
  209. {
  210. CATransition *transition = [CATransition animation];
  211. transition.duration = 0.25;
  212. transition.type = kCATransitionFade;
  213. [self.view.layer addAnimation:transition forKey:kCATransition];
  214. [self popToRootViewControllerAnimated:NO];
  215. }
  216. else
  217. {
  218. [self popToRootViewControllerAnimated:animated];
  219. }
  220. return;
  221. }
  222. // resetTo
  223. if ([performAction isEqualToString:@"resetTo"])
  224. {
  225. NSArray<UIViewController *> *viewControllers;
  226. NSString *component = actionParams[@"component"];
  227. NSArray<NSDictionary *> *componentConfigs = actionParams[@"components"];
  228. if (component) {
  229. NSMutableDictionary *passProps = [actionParams[@"passProps"] mutableCopy];
  230. passProps[@"commandType"] = @"resetTo";
  231. NSDictionary *style = actionParams[@"style"];
  232. NSArray *leftButtons = actionParams[@"leftButtons"];
  233. NSArray *rightButtons = actionParams[@"rightButtons"];
  234. UIViewController *viewController = [self viewControllerWithComponent:component
  235. props:[passProps copy]
  236. style:style
  237. leftButtons:leftButtons
  238. rightButtons:rightButtons
  239. bridge:bridge];
  240. NSDictionary *navigatorStyle = actionParams[@"style"];
  241. [self processTitleView:viewController
  242. props:actionParams
  243. style:navigatorStyle];
  244. viewControllers = @[viewController];
  245. } else if (componentConfigs) {
  246. NSMutableArray *mutableViewControllers = [NSMutableArray arrayWithCapacity:[componentConfigs count]];
  247. [componentConfigs enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull config, NSUInteger idx, BOOL * _Nonnull stop) {
  248. NSString *component = config[@"component"];
  249. NSMutableDictionary *props = [config[@"passProps"] mutableCopy];
  250. props[@"commandType"] = @"resetTo";
  251. NSDictionary *style = config[@"style"];
  252. NSArray *leftButtons = config[@"leftButtons"];
  253. NSArray *rightButtons = config[@"rightButtons"];
  254. UIViewController *viewController = [self viewControllerWithComponent:component
  255. props:[props copy]
  256. style:style
  257. leftButtons:leftButtons
  258. rightButtons:rightButtons
  259. bridge:bridge];
  260. [self processTitleView:viewController
  261. props:actionParams
  262. style:style];
  263. [mutableViewControllers addObject:viewController];
  264. }];
  265. viewControllers = [mutableViewControllers copy];
  266. }
  267. if (!viewControllers) return;
  268. BOOL animated = actionParams[@"animated"] ? [actionParams[@"animated"] boolValue] : YES;
  269. NSString *animationType = actionParams[@"animationType"];
  270. if ([animationType isEqualToString:@"fade"])
  271. {
  272. CATransition *transition = [CATransition animation];
  273. transition.duration = 0.25;
  274. transition.type = kCATransitionFade;
  275. [self.view.layer addAnimation:transition forKey:kCATransition];
  276. [self setViewControllers:viewControllers animated:NO];
  277. }
  278. else
  279. {
  280. [self setViewControllers:viewControllers animated:animated];
  281. }
  282. return;
  283. }
  284. // setButtons
  285. if ([performAction isEqualToString:@"setButtons"])
  286. {
  287. NSArray *buttons = actionParams[@"buttons"];
  288. BOOL animated = actionParams[@"animated"] ? [actionParams[@"animated"] boolValue] : YES;
  289. NSString *side = actionParams[@"side"] ? actionParams[@"side"] : @"left";
  290. [self setButtons:buttons viewController:self.topViewController side:side animated:animated];
  291. return;
  292. }
  293. // setTitle
  294. if ([performAction isEqualToString:@"setTitle"] || [performAction isEqualToString:@"setTitleImage"])
  295. {
  296. NSDictionary *navigatorStyle = actionParams[@"style"];
  297. [self processTitleView:self.topViewController
  298. props:actionParams
  299. style:navigatorStyle];
  300. return;
  301. }
  302. // toggleNavBar
  303. if ([performAction isEqualToString:@"setHidden"]) {
  304. NSNumber *animated = actionParams[@"animated"];
  305. BOOL animatedBool = animated ? [animated boolValue] : YES;
  306. NSNumber *setHidden = actionParams[@"hidden"];
  307. BOOL isHiddenBool = setHidden ? [setHidden boolValue] : NO;
  308. RCCViewController *topViewController = ((RCCViewController*)self.topViewController);
  309. topViewController.navigatorStyle[@"navBarHidden"] = setHidden;
  310. [topViewController setNavBarVisibilityChange:animatedBool];
  311. }
  312. // setStyle
  313. if ([performAction isEqualToString:@"setStyle"])
  314. {
  315. NSDictionary *navigatorStyle = actionParams;
  316. // merge the navigatorStyle of our parent
  317. if ([self.topViewController isKindOfClass:[RCCViewController class]])
  318. {
  319. RCCViewController *parent = (RCCViewController*)self.topViewController;
  320. NSMutableDictionary *mergedStyle = [NSMutableDictionary dictionaryWithDictionary:parent.navigatorStyle];
  321. // there are a few styles that we don't want to remember from our parent (they should be local)
  322. [mergedStyle setValuesForKeysWithDictionary:navigatorStyle];
  323. navigatorStyle = mergedStyle;
  324. parent.navigatorStyle = navigatorStyle;
  325. [parent setStyleOnInit];
  326. [parent updateStyle];
  327. }
  328. }
  329. }
  330. - (UIViewController *)viewControllerWithComponent:(NSString *)component
  331. props:(NSDictionary *)props
  332. style:(NSDictionary *)style
  333. leftButtons:(NSArray<NSDictionary *> *)leftButtons
  334. rightButtons:(NSArray<NSDictionary *> *)rightButtons
  335. bridge:(RCTBridge *)bridge
  336. {
  337. RCCViewController *viewController = [[RCCViewController alloc] initWithComponent:component
  338. passProps:props
  339. navigatorStyle:style
  340. globalProps:nil
  341. bridge:bridge];
  342. viewController.controllerId = props[@"screenInstanceID"];
  343. viewController.navigationItem.hidesBackButton = YES;
  344. [self processTitleView:viewController
  345. props:props
  346. style:style];
  347. if (leftButtons)
  348. {
  349. [self setButtons:leftButtons viewController:viewController side:@"left" animated:NO];
  350. }
  351. if (rightButtons)
  352. {
  353. [self setButtons:rightButtons viewController:viewController side:@"right" animated:NO];
  354. }
  355. return viewController;
  356. }
  357. -(void)onButtonPress:(UIBarButtonItem*)barButtonItem
  358. {
  359. NSString *callbackId = objc_getAssociatedObject(barButtonItem, &CALLBACK_ASSOCIATED_KEY);
  360. if (!callbackId) return;
  361. NSString *buttonId = objc_getAssociatedObject(barButtonItem, &CALLBACK_ASSOCIATED_ID);
  362. [[[RCCManager sharedInstance] getBridge].eventDispatcher sendAppEventWithName:callbackId body:@
  363. {
  364. @"type": @"NavBarButtonPress",
  365. @"id": buttonId ? buttonId : [NSNull null]
  366. }];
  367. }
  368. -(void)setButtons:(NSArray*)buttons viewController:(UIViewController*)viewController side:(NSString*)side animated:(BOOL)animated
  369. {
  370. NSMutableArray *barButtonItems = [NSMutableArray new];
  371. for (NSDictionary *button in buttons)
  372. {
  373. NSString *title = button[@"title"];
  374. UIImage *iconImage = nil;
  375. id icon = button[@"icon"];
  376. if (icon) iconImage = [RCTConvert UIImage:icon];
  377. NSString *__nullable component = button[@"component"];
  378. NSString *__nullable systemItemName = button[@"systemItem"];
  379. UIBarButtonSystemItem systemItem = [RCTConvert UIBarButtonSystemItem:systemItemName];
  380. UIBarButtonItem *barButtonItem;
  381. if (iconImage)
  382. {
  383. barButtonItem = [[UIBarButtonItem alloc] initWithImage:iconImage style:UIBarButtonItemStylePlain target:self action:@selector(onButtonPress:)];
  384. }
  385. else if (title)
  386. {
  387. barButtonItem = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStylePlain target:self action:@selector(onButtonPress:)];
  388. NSMutableDictionary *buttonTextAttributes = [RCTHelpers textAttributesFromDictionary:button withPrefix:@"button"];
  389. if (buttonTextAttributes.allKeys.count > 0) {
  390. [barButtonItem setTitleTextAttributes:buttonTextAttributes forState:UIControlStateNormal];
  391. [barButtonItem setTitleTextAttributes:buttonTextAttributes forState:UIControlStateHighlighted];
  392. }
  393. }
  394. else if (component) {
  395. RCTBridge *bridge = [[RCCManager sharedInstance] getBridge];
  396. barButtonItem = [[RCCCustomBarButtonItem alloc] initWithComponentName:component passProps:button[@"passProps"] bridge:bridge];
  397. }
  398. else if (systemItemName) {
  399. barButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:systemItem target:self action:@selector(onButtonPress:)];
  400. }
  401. else continue;
  402. objc_setAssociatedObject(barButtonItem, &CALLBACK_ASSOCIATED_KEY, button[@"onPress"], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  403. [barButtonItems addObject:barButtonItem];
  404. NSString *buttonId = button[@"id"];
  405. if (buttonId)
  406. {
  407. objc_setAssociatedObject(barButtonItem, &CALLBACK_ASSOCIATED_ID, buttonId, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  408. }
  409. NSNumber *disabled = button[@"disabled"];
  410. BOOL disabledBool = disabled ? [disabled boolValue] : NO;
  411. if (disabledBool) {
  412. [barButtonItem setEnabled:NO];
  413. }
  414. NSNumber *disableIconTintString = button[@"disableIconTint"];
  415. BOOL disableIconTint = disableIconTintString ? [disableIconTintString boolValue] : NO;
  416. if (disableIconTint) {
  417. [barButtonItem setImage:[barButtonItem.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
  418. }
  419. if ([viewController isKindOfClass:[RCCViewController class]]) {
  420. RCCViewController *rccViewController = ((RCCViewController*)viewController);
  421. NSDictionary *navigatorStyle = rccViewController.navigatorStyle;
  422. id disabledButtonColor = navigatorStyle[@"disabledButtonColor"];
  423. if (disabledButtonColor) {
  424. UIColor *color = [RCTConvert UIColor:disabledButtonColor];
  425. [barButtonItem setTitleTextAttributes:@{NSForegroundColorAttributeName : color} forState:UIControlStateDisabled];
  426. }
  427. }
  428. NSString *testID = button[@"testID"];
  429. if (testID)
  430. {
  431. barButtonItem.accessibilityIdentifier = testID;
  432. }
  433. }
  434. if ([side isEqualToString:@"left"])
  435. {
  436. [viewController.navigationItem setLeftBarButtonItems:barButtonItems animated:animated];
  437. }
  438. if ([side isEqualToString:@"right"])
  439. {
  440. [viewController.navigationItem setRightBarButtonItems:barButtonItems animated:animated];
  441. }
  442. }
  443. -(void)processTitleView:(UIViewController*)viewController
  444. props:(NSDictionary*)props
  445. style:(NSDictionary*)style
  446. {
  447. BOOL isSetSubtitleBool = props[@"isSetSubtitle"] ? [props[@"isSetSubtitle"] boolValue] : NO;
  448. RCCTitleViewHelper *titleViewHelper = [[RCCTitleViewHelper alloc] init:viewController
  449. navigationController:self
  450. title:props[@"title"]
  451. subtitle:props[@"subtitle"]
  452. titleImageData:props[@"titleImage"]
  453. isSetSubtitle:isSetSubtitleBool];
  454. [titleViewHelper setup:style];
  455. }
  456. - (UIStatusBarStyle)preferredStatusBarStyle {
  457. return [self.topViewController preferredStatusBarStyle];
  458. }
  459. - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
  460. {
  461. if(_transitioning)
  462. {
  463. NSDictionary *pushDetails =@{ @"viewController": viewController, @"animated": @(animated) };
  464. [_queuedViewControllers addObject:pushDetails];
  465. return;
  466. }
  467. _transitioning = YES;
  468. [super pushViewController:viewController animated:animated];
  469. }
  470. #pragma mark - UINavigationControllerDelegate
  471. -(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  472. [viewController setNeedsStatusBarAppearanceUpdate];
  473. }
  474. - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
  475. {
  476. dispatch_async(dispatch_get_main_queue(), ^{
  477. _transitioning = NO;
  478. if ([_queuedViewControllers count] > 0) {
  479. NSDictionary *toPushDetails = [_queuedViewControllers firstObject];
  480. [_queuedViewControllers removeObjectAtIndex:0];
  481. [self pushViewController:toPushDetails[@"viewController"] animated:[toPushDetails[@"animated"] boolValue]];
  482. }
  483. });
  484. }
  485. @end