react-native-navigation的迁移库

RNNStackController.m 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. - (UIModalPresentationStyle)modalPresentationStyle {
  34. return self.getCurrentChild.modalPresentationStyle;
  35. }
  36. - (UIViewController *)popViewControllerAnimated:(BOOL)animated {
  37. [self prepareForPop];
  38. return [super popViewControllerAnimated:animated];
  39. }
  40. - (void)prepareForPop {
  41. if (self.viewControllers.count > 1) {
  42. UIViewController *controller = self.viewControllers[self.viewControllers.count - 2];
  43. if ([controller isKindOfClass:[RNNComponentViewController class]]) {
  44. RNNComponentViewController *rnnController = (RNNComponentViewController *)controller;
  45. [self.presenter applyOptionsBeforePopping:rnnController.resolveOptions];
  46. }
  47. }
  48. }
  49. - (UIViewController *)childViewControllerForStatusBarStyle {
  50. return self.topViewController;
  51. }
  52. @end