react-native-navigation的迁移库

RNNStackController.m 2.4KB

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