react-native-navigation的迁移库

RNNRootViewController.m 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #import "RNNRootViewController.h"
  2. #import <React/RCTConvert.h>
  3. #import "RNNAnimator.h"
  4. #import "RNNNavigationButtons.h"
  5. @interface RNNRootViewController()
  6. @property (nonatomic, strong) NSString* containerName;
  7. @property (nonatomic) BOOL _statusBarHidden;
  8. @property (nonatomic, strong) RNNNavigationButtons* navigationButtons;
  9. @end
  10. @implementation RNNRootViewController
  11. -(instancetype)initWithName:(NSString*)name
  12. withOptions:(RNNNavigationOptions*)options
  13. withContainerId:(NSString*)containerId
  14. rootViewCreator:(id<RNNRootViewCreator>)creator
  15. eventEmitter:(RNNEventEmitter*)eventEmitter
  16. animator:(RNNAnimator *)animator {
  17. self = [super init];
  18. self.containerId = containerId;
  19. self.containerName = name;
  20. self.navigationOptions = options;
  21. self.eventEmitter = eventEmitter;
  22. self.animator = animator;
  23. self.view = [creator createRootView:self.containerName rootViewId:self.containerId];
  24. [[NSNotificationCenter defaultCenter] addObserver:self
  25. selector:@selector(onJsReload)
  26. name:RCTJavaScriptWillStartLoadingNotification
  27. object:nil];
  28. self.navigationController.modalPresentationStyle = UIModalPresentationCustom;
  29. self.navigationController.delegate = self;
  30. self.navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:self];
  31. return self;
  32. }
  33. -(void)viewWillAppear:(BOOL)animated{
  34. [super viewWillAppear:animated];
  35. [self.navigationOptions applyOn:self];
  36. [self applyNavigationButtons];
  37. }
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. }
  41. -(BOOL)isAnimated {
  42. return self.animator;
  43. }
  44. - (BOOL)prefersStatusBarHidden {
  45. if ([self.navigationOptions.statusBarHidden boolValue]) {
  46. return YES;
  47. } else if ([self.navigationOptions.statusBarHideWithTopBar boolValue]) {
  48. return self.navigationController.isNavigationBarHidden;
  49. }
  50. return NO;
  51. }
  52. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  53. return self.navigationOptions.supportedOrientations;
  54. }
  55. - (BOOL)hidesBottomBarWhenPushed
  56. {
  57. if (self.navigationOptions.bottomTabs && self.navigationOptions.bottomTabs.hidden) {
  58. return [self.navigationOptions.bottomTabs.hidden boolValue];
  59. }
  60. return NO;
  61. }
  62. -(void)viewDidAppear:(BOOL)animated {
  63. [super viewDidAppear:animated];
  64. [self.eventEmitter sendContainerDidAppear:self.containerId];
  65. }
  66. -(void)viewDidDisappear:(BOOL)animated {
  67. [super viewDidDisappear:animated];
  68. [self.eventEmitter sendContainerDidDisappear:self.containerId];
  69. }
  70. - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
  71. RNNRootViewController* vc = (RNNRootViewController*)viewController;
  72. if (![vc.navigationOptions.backButtonTransition isEqualToString:@"custom"]){
  73. navigationController.delegate = nil;
  74. }
  75. }
  76. - (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
  77. animationControllerForOperation:(UINavigationControllerOperation)operation
  78. fromViewController:(UIViewController*)fromVC
  79. toViewController:(UIViewController*)toVC {
  80. {
  81. if (operation == UINavigationControllerOperationPush) {
  82. return self.animator;
  83. } else if (operation == UINavigationControllerOperationPop) {
  84. return self.animator;
  85. } else {
  86. return nil;
  87. }
  88. }
  89. return nil;
  90. }
  91. -(void)applyNavigationButtons{
  92. [self.navigationButtons applyLeftButtons:self.navigationOptions.leftButtons rightButtons:self.navigationOptions.rightButtons];
  93. }
  94. -(void)applyTabBarItem {
  95. [self.navigationOptions applyTabBarItemOptions:self];
  96. }
  97. /**
  98. * fix for #877, #878
  99. */
  100. -(void)onJsReload {
  101. [self cleanReactLeftovers];
  102. }
  103. /**
  104. * fix for #880
  105. */
  106. -(void)dealloc {
  107. [self cleanReactLeftovers];
  108. }
  109. -(void)cleanReactLeftovers {
  110. [[NSNotificationCenter defaultCenter] removeObserver:self];
  111. [[NSNotificationCenter defaultCenter] removeObserver:self.view];
  112. self.view = nil;
  113. }
  114. @end