react-native-navigation的迁移库

RNNRootViewController.m 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #import "RNNRootViewController.h"
  2. #import <React/RCTConvert.h>
  3. #import "RNNNavigationButtons.h"
  4. @interface RNNRootViewController()
  5. @property (nonatomic, strong) NSString* containerName;
  6. @property (nonatomic) BOOL _statusBarHidden;
  7. @property (nonatomic, strong) RNNNavigationButtons* navigationButtons;
  8. @end
  9. @implementation RNNRootViewController
  10. -(instancetype)initWithName:(NSString*)name
  11. withOptions:(RNNNavigationOptions*)options
  12. withContainerId:(NSString*)containerId
  13. rootViewCreator:(id<RNNRootViewCreator>)creator
  14. eventEmitter:(RNNEventEmitter*)eventEmitter {
  15. self = [super init];
  16. self.containerId = containerId;
  17. self.containerName = name;
  18. self.navigationOptions = options;
  19. self.eventEmitter = eventEmitter;
  20. self.view = [creator createRootView:self.containerName rootViewId:self.containerId];
  21. [[NSNotificationCenter defaultCenter] addObserver:self
  22. selector:@selector(onJsReload)
  23. name:RCTJavaScriptWillStartLoadingNotification
  24. object:nil];
  25. self.navigationButtons = [[RNNNavigationButtons alloc] initWithViewController:self];
  26. return self;
  27. }
  28. -(void)viewWillAppear:(BOOL)animated{
  29. [super viewWillAppear:animated];
  30. [self.navigationOptions applyOn:self];
  31. [self applyNavigationButtons];
  32. }
  33. - (BOOL)prefersStatusBarHidden {
  34. if ([self.navigationOptions.statusBarHidden boolValue]) {
  35. return YES;
  36. } else if ([self.navigationOptions.statusBarHideWithTopBar boolValue]) {
  37. return self.navigationController.isNavigationBarHidden;
  38. }
  39. return NO;
  40. }
  41. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  42. return self.navigationOptions.supportedOrientations;
  43. }
  44. - (BOOL)hidesBottomBarWhenPushed
  45. {
  46. if (self.navigationOptions.tabBarHidden) {
  47. return [self.navigationOptions.tabBarHidden boolValue];
  48. }
  49. return NO;
  50. }
  51. -(void)viewDidAppear:(BOOL)animated {
  52. [super viewDidAppear:animated];
  53. [self.eventEmitter sendContainerDidAppear:self.containerId];
  54. }
  55. -(void)viewDidDisappear:(BOOL)animated {
  56. [super viewDidDisappear:animated];
  57. [self.eventEmitter sendContainerDidDisappear:self.containerId];
  58. }
  59. -(void) applyNavigationButtons{
  60. [self.navigationButtons applyLeftButtons:self.navigationOptions.leftButtons rightButtons:self.navigationOptions.rightButtons];
  61. }
  62. /**
  63. * fix for #877, #878
  64. */
  65. -(void)onJsReload {
  66. [self cleanReactLeftovers];
  67. }
  68. /**
  69. * fix for #880
  70. */
  71. -(void)dealloc {
  72. [self cleanReactLeftovers];
  73. }
  74. -(void)cleanReactLeftovers {
  75. [[NSNotificationCenter defaultCenter] removeObserver:self];
  76. [[NSNotificationCenter defaultCenter] removeObserver:self.view];
  77. self.view = nil;
  78. }
  79. @end