react-native-navigation的迁移库

RCCNavigationController.m 25KB

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