react-native-navigation的迁移库

RNNNavigationController.m 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 presenter:(RNNNavigationControllerPresenter *)presenter {
  6. self = [super init];
  7. self.presenter = presenter;
  8. self.options = options;
  9. self.layoutInfo = layoutInfo;
  10. [self setViewControllers:childViewControllers];
  11. return self;
  12. }
  13. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  14. return self.viewControllers.lastObject.supportedInterfaceOrientations;
  15. }
  16. - (UINavigationController *)navigationController {
  17. return self;
  18. }
  19. - (UIStatusBarStyle)preferredStatusBarStyle {
  20. return self.getLeafViewController.preferredStatusBarStyle;
  21. }
  22. - (UIModalPresentationStyle)modalPresentationStyle {
  23. return self.getLeafViewController.modalPresentationStyle;
  24. }
  25. - (UIViewController *)popViewControllerAnimated:(BOOL)animated {
  26. if (self.viewControllers.count > 1) {
  27. UIViewController *controller = self.viewControllers[self.viewControllers.count - 2];
  28. if ([controller isKindOfClass:[RNNRootViewController class]]) {
  29. RNNRootViewController *rnnController = (RNNRootViewController *)controller;
  30. [rnnController.presenter present:rnnController.options onViewControllerDidLoad:rnnController];
  31. }
  32. }
  33. return [super popViewControllerAnimated:animated];
  34. }
  35. - (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
  36. return [[RNNModalAnimation alloc] initWithScreenTransition:self.getLeafViewController.options.animations.showModal isDismiss:NO];
  37. }
  38. - (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
  39. return [[RNNModalAnimation alloc] initWithScreenTransition:self.getLeafViewController.options.animations.dismissModal isDismiss:YES];
  40. }
  41. - (UIViewController *)getLeafViewController {
  42. return ((UIViewController<RNNParentProtocol>*)self.topViewController);
  43. }
  44. - (UIViewController *)childViewControllerForStatusBarStyle {
  45. return self.topViewController;
  46. }
  47. - (void)willMoveToParentViewController:(UIViewController *)parent {
  48. [_presenter present:self.options onViewControllerDidLoad:self];
  49. }
  50. @end