react-native-navigation的迁移库

RNNNavigationController.m 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #import "RNNNavigationController.h"
  2. #import "RNNModalAnimation.h"
  3. #import "RNNRootViewController.h"
  4. @implementation RNNNavigationController
  5. - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo childViewControllers:(NSArray *)childViewControllers options:(RNNNavigationOptions *)options optionsResolver:(RNNParentOptionsResolver *)optionsResolver presenter:(RNNNavigationControllerPresenter *)presenter {
  6. self = [super init];
  7. self.presenter = presenter;
  8. self.options = options;
  9. self.optionsResolver = optionsResolver;
  10. self.layoutInfo = layoutInfo;
  11. [self setViewControllers:childViewControllers];
  12. return self;
  13. }
  14. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  15. return self.viewControllers.lastObject.supportedInterfaceOrientations;
  16. }
  17. - (UINavigationController *)navigationController {
  18. return self;
  19. }
  20. - (UIStatusBarStyle)preferredStatusBarStyle {
  21. return self.getLeafViewController.preferredStatusBarStyle;
  22. }
  23. - (UIModalPresentationStyle)modalPresentationStyle {
  24. return self.getLeafViewController.modalPresentationStyle;
  25. }
  26. - (UIViewController *)popViewControllerAnimated:(BOOL)animated {
  27. if (self.viewControllers.count > 1) {
  28. UIViewController *controller = self.viewControllers[self.viewControllers.count - 2];
  29. if ([controller isKindOfClass:[RNNRootViewController class]]) {
  30. RNNRootViewController *rnnController = (RNNRootViewController *)controller;
  31. [rnnController.presenter present:rnnController.options onViewControllerDidLoad:rnnController];
  32. }
  33. }
  34. return [super popViewControllerAnimated:animated];
  35. }
  36. - (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
  37. return [[RNNModalAnimation alloc] initWithScreenTransition:self.getLeafViewController.options.animations.showModal isDismiss:NO];
  38. }
  39. - (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
  40. return [[RNNModalAnimation alloc] initWithScreenTransition:self.getLeafViewController.options.animations.dismissModal isDismiss:YES];
  41. }
  42. - (UIViewController *)getLeafViewController {
  43. return ((UIViewController<RNNParentProtocol>*)self.topViewController);
  44. }
  45. - (UIViewController *)childViewControllerForStatusBarStyle {
  46. return self.topViewController;
  47. }
  48. - (void)viewDidLoad {
  49. [super viewDidLoad];
  50. [_presenter present:self.options onViewControllerDidLoad:self];
  51. }
  52. - (void)willMoveToParentViewController:(UIViewController *)parent {
  53. [_optionsResolver resolve:self with:self.childViewControllers];
  54. [_presenter present:self.options onViewControllerDidLoad:self];
  55. }
  56. - (void)mergeOptions:(RNNNavigationOptions *)options {
  57. [self.presenter present:options onViewControllerWillAppear:self];
  58. }
  59. @end