react-native-navigation的迁移库

RNNStackController.m 2.5KB

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