react-native-navigation的迁移库

RNNRootViewController.m 3.5KB

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