react-native-navigation的迁移库

RNNRootViewController.m 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. -(void)viewDidAppear:(BOOL)animated {
  42. [super viewDidAppear:animated];
  43. [self.eventEmitter sendContainerDidAppear:self.containerId];
  44. }
  45. -(void)viewDidDisappear:(BOOL)animated {
  46. [super viewDidDisappear:animated];
  47. [self.eventEmitter sendContainerDidDisappear:self.containerId];
  48. }
  49. -(void) applyNavigationButtons{
  50. [self.navigationButtons applyLeftButtons:self.navigationOptions.leftButtons rightButtons:self.navigationOptions.rightButtons];
  51. }
  52. /**
  53. * fix for #877, #878
  54. */
  55. -(void)onJsReload {
  56. [self cleanReactLeftovers];
  57. }
  58. /**
  59. * fix for #880
  60. */
  61. -(void)dealloc {
  62. [self cleanReactLeftovers];
  63. }
  64. -(void)cleanReactLeftovers {
  65. [[NSNotificationCenter defaultCenter] removeObserver:self];
  66. [[NSNotificationCenter defaultCenter] removeObserver:self.view];
  67. self.view = nil;
  68. }
  69. @end