react-native-navigation的迁移库

RCCNavigationController.m 25KB

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