react-native-navigation的迁移库

RNNNavigationController.m 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #import "RNNNavigationController.h"
  2. #import "RNNModalAnimation.h"
  3. #import "RNNRootViewController.h"
  4. @implementation RNNNavigationController
  5. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  6. return self.viewControllers.lastObject.supportedInterfaceOrientations;
  7. }
  8. - (UINavigationController *)navigationController {
  9. return self;
  10. }
  11. - (UIStatusBarStyle)preferredStatusBarStyle {
  12. return self.getLeafViewController.preferredStatusBarStyle;
  13. }
  14. - (UIModalPresentationStyle)modalPresentationStyle {
  15. return self.getLeafViewController.modalPresentationStyle;
  16. }
  17. - (UIViewController *)popViewControllerAnimated:(BOOL)animated {
  18. if (self.viewControllers.count > 1) {
  19. UIViewController *controller = self.viewControllers[self.viewControllers.count - 2];
  20. if ([controller isKindOfClass:[RNNRootViewController class]]) {
  21. RNNRootViewController *rnnController = (RNNRootViewController *)controller;
  22. [rnnController.presenter presentOn:rnnController];
  23. }
  24. }
  25. return [super popViewControllerAnimated:animated];
  26. }
  27. - (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
  28. return [[RNNModalAnimation alloc] initWithScreenTransition:self.getLeafViewController.presenter.options.animations.showModal isDismiss:NO];
  29. }
  30. - (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
  31. return [[RNNModalAnimation alloc] initWithScreenTransition:self.getLeafViewController.presenter.options.animations.dismissModal isDismiss:YES];
  32. }
  33. - (UIViewController *)getLeafViewController {
  34. return ((UIViewController<RNNParentProtocol>*)self.topViewController);
  35. }
  36. - (UIViewController *)childViewControllerForStatusBarStyle {
  37. return self.topViewController;
  38. }
  39. - (void)willMoveToParentViewController:(UIViewController *)parent {
  40. if ([self.parentViewController respondsToSelector:@selector(performOnChildLoad:)]) {
  41. [self.parentViewController performSelector:@selector(performOnChildLoad:) withObject:_presenter.options];
  42. }
  43. }
  44. - (void)performOnChildWillAppear:(RNNNavigationOptions *)childOptions {
  45. RNNNavigationOptions* combinedOptions = [_presenter presentWithChildOptions:childOptions on:self];
  46. if ([self.parentViewController respondsToSelector:@selector(performOnChildWillAppear:)]) {
  47. [self.parentViewController performSelector:@selector(performOnChildWillAppear:) withObject:combinedOptions];
  48. }
  49. }
  50. - (void)performOnChildLoad:(RNNNavigationOptions *)childOptions {
  51. RNNNavigationOptions* combinedOptions = [_presenter presentWithChildOptions:childOptions on:self];
  52. if ([self.parentViewController respondsToSelector:@selector(performOnChildLoad:)]) {
  53. [self.parentViewController performSelector:@selector(performOnChildLoad:) withObject:combinedOptions];
  54. }
  55. }
  56. @end