react-native-navigation的迁移库

RNNStackController.m 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. self.navigationBar.prefersLargeTitles = YES;
  14. return self;
  15. }
  16. - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
  17. [super setDefaultOptions:defaultOptions];
  18. [self.presenter setDefaultOptions:defaultOptions];
  19. }
  20. - (void)viewDidLayoutSubviews {
  21. [super viewDidLayoutSubviews];
  22. [self.presenter applyOptionsOnViewDidLayoutSubviews:self.resolveOptions];
  23. }
  24. - (void)mergeChildOptions:(RNNNavigationOptions *)options child:(UIViewController *)child {
  25. if (child.isLastInStack) {
  26. [self.presenter mergeOptions:options resolvedOptions:self.resolveOptions];
  27. }
  28. [self.parentViewController mergeChildOptions:options child:child];
  29. }
  30. - (UIStatusBarStyle)preferredStatusBarStyle {
  31. return [_presenter getStatusBarStyle:self.resolveOptions];
  32. }
  33. - (UIViewController *)popViewControllerAnimated:(BOOL)animated {
  34. [self prepareForPop];
  35. return [super popViewControllerAnimated:animated];
  36. }
  37. - (void)prepareForPop {
  38. if (self.viewControllers.count > 1) {
  39. UIViewController *controller = self.viewControllers[self.viewControllers.count - 2];
  40. if ([controller isKindOfClass:[RNNComponentViewController class]]) {
  41. RNNComponentViewController *rnnController = (RNNComponentViewController *)controller;
  42. [self.presenter applyOptionsBeforePopping:rnnController.resolveOptions];
  43. }
  44. }
  45. }
  46. - (UIViewController *)childViewControllerForStatusBarStyle {
  47. return self.topViewController;
  48. }
  49. @end