react-native-navigation的迁移库

RNNRootViewController.m 3.6KB

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