react-native-navigation的迁移库

RNNRootViewController.m 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #import "RNNRootViewController.h"
  2. #import <React/RCTConvert.h>
  3. @interface RNNRootViewController()
  4. @property (nonatomic, strong) NSString* containerId;
  5. @property (nonatomic, strong) NSString* containerName;
  6. @property (nonatomic, strong) RNNEventEmitter *eventEmitter;
  7. @property (nonatomic) BOOL _statusBarHidden;
  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. return self;
  26. }
  27. -(void)viewWillAppear:(BOOL)animated{
  28. [super viewWillAppear:animated];
  29. [self.navigationOptions applyOn:self];
  30. }
  31. - (BOOL)prefersStatusBarHidden {
  32. if ([self.navigationOptions.statusBarHidden boolValue]) {
  33. return YES;
  34. } else if ([self.navigationOptions.statusBarHideWithTopBar boolValue]) {
  35. return self.navigationController.isNavigationBarHidden;
  36. }
  37. return NO;
  38. }
  39. -(void)viewDidAppear:(BOOL)animated {
  40. [super viewDidAppear:animated];
  41. [self.eventEmitter sendContainerDidAppear:self.containerId];
  42. }
  43. -(void)viewDidDisappear:(BOOL)animated {
  44. [super viewDidDisappear:animated];
  45. [self.eventEmitter sendContainerDidDisappear:self.containerId];
  46. }
  47. /**
  48. * fix for #877, #878
  49. */
  50. -(void)onJsReload {
  51. [self cleanReactLeftovers];
  52. }
  53. /**
  54. * fix for #880
  55. */
  56. -(void)dealloc {
  57. [self cleanReactLeftovers];
  58. }
  59. -(void)cleanReactLeftovers {
  60. [[NSNotificationCenter defaultCenter] removeObserver:self];
  61. [[NSNotificationCenter defaultCenter] removeObserver:self.view];
  62. self.view = nil;
  63. }
  64. @end