react-native-navigation的迁移库

RNNNavigationController.m 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.options mergeOptions:options overrideOptions:YES];
  58. [self.presenter present:self.options onViewControllerWillAppear:self];
  59. }
  60. @end