react-native-navigation的迁移库

RNNStackController.m 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #import "RNNStackController.h"
  2. #import "RNNComponentViewController.h"
  3. #import "UIViewController+Utils.h"
  4. #import "StackControllerDelegate.h"
  5. @implementation RNNStackController {
  6. UIViewController* _presentedViewController;
  7. StackControllerDelegate* _stackDelegate;
  8. }
  9. - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo creator:(id<RNNComponentViewCreator>)creator options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions presenter:(RNNBasePresenter *)presenter eventEmitter:(RNNEventEmitter *)eventEmitter childViewControllers:(NSArray *)childViewControllers {
  10. self = [super initWithLayoutInfo:layoutInfo creator:creator options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:eventEmitter childViewControllers:childViewControllers];
  11. _stackDelegate = [[StackControllerDelegate alloc] initWithEventEmitter:self.eventEmitter];
  12. self.delegate = _stackDelegate;
  13. if (@available(iOS 11.0, *)) {
  14. self.navigationBar.prefersLargeTitles = YES;
  15. }
  16. return self;
  17. }
  18. - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
  19. [super setDefaultOptions:defaultOptions];
  20. [self.presenter setDefaultOptions:defaultOptions];
  21. }
  22. - (void)viewDidLayoutSubviews {
  23. [super viewDidLayoutSubviews];
  24. [self.presenter applyOptionsOnViewDidLayoutSubviews:self.resolveOptions];
  25. }
  26. - (void)mergeChildOptions:(RNNNavigationOptions *)options child:(UIViewController *)child {
  27. if (child.isLastInStack) {
  28. [self.presenter mergeOptions:options resolvedOptions:self.resolveOptions];
  29. }
  30. [self.parentViewController mergeChildOptions:options child:child];
  31. }
  32. - (UIViewController *)popViewControllerAnimated:(BOOL)animated {
  33. [self prepareForPop];
  34. return [super popViewControllerAnimated:animated];
  35. }
  36. - (void)prepareForPop {
  37. if (self.viewControllers.count > 1) {
  38. UIViewController *controller = self.viewControllers[self.viewControllers.count - 2];
  39. if ([controller isKindOfClass:[RNNComponentViewController class]]) {
  40. RNNComponentViewController *rnnController = (RNNComponentViewController *)controller;
  41. [self.presenter applyOptionsBeforePopping:rnnController.resolveOptions];
  42. }
  43. }
  44. }
  45. - (UIViewController *)childViewControllerForStatusBarStyle {
  46. return self.topViewController;
  47. }
  48. # pragma mark - UIViewController overrides
  49. - (void)willMoveToParentViewController:(UIViewController *)parent {
  50. [self.presenter willMoveToParentViewController:parent];
  51. }
  52. - (UIStatusBarStyle)preferredStatusBarStyle {
  53. return [self.presenter getStatusBarStyle];
  54. }
  55. - (BOOL)prefersStatusBarHidden {
  56. return [self.presenter getStatusBarVisibility];
  57. }
  58. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  59. return [self.presenter getOrientation];
  60. }
  61. - (BOOL)hidesBottomBarWhenPushed {
  62. return [self.presenter hidesBottomBarWhenPushed];
  63. }
  64. @end