react-native-navigation的迁移库

RNNRootViewController.m 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #import "RNNRootViewController.h"
  2. @interface RNNRootViewController()
  3. @property (nonatomic, strong) NSString* containerId;
  4. @property (nonatomic, strong) NSString* containerName;
  5. @property (nonatomic, strong) RNNEventEmitter *eventEmitter;
  6. @property (nonatomic) BOOL _statusBarHidden;
  7. @end
  8. @implementation RNNRootViewController
  9. -(instancetype)initWithNode:(RNNLayoutNode*)node rootViewCreator:(id<RNNRootViewCreator>)creator eventEmitter:(RNNEventEmitter*)eventEmitter {
  10. self = [super init];
  11. self.containerId = node.nodeId;
  12. self.containerName = node.data[@"name"];
  13. self.eventEmitter = eventEmitter;
  14. self.view = [creator createRootView:self.containerName rootViewId:self.containerId];
  15. [[NSNotificationCenter defaultCenter] addObserver:self
  16. selector:@selector(onJsReload)
  17. name:RCTJavaScriptWillStartLoadingNotification
  18. object:nil];
  19. self.navigationItem.title = node.data[@"navigationOptions"][@"title"];
  20. self._statusBarHidden = [(NSNumber*)node.data[@"navigationOptions"][@"statusBarHidden"] boolValue];
  21. return self;
  22. }
  23. - (BOOL)prefersStatusBarHidden {
  24. return self._statusBarHidden; // || self.navigationController.isNavigationBarHidden;
  25. }
  26. -(void)viewDidAppear:(BOOL)animated {
  27. [super viewDidAppear:animated];
  28. [self.eventEmitter sendContainerStart:self.containerId];
  29. }
  30. -(void)viewDidDisappear:(BOOL)animated {
  31. [super viewDidDisappear:animated];
  32. [self.eventEmitter sendContainerStop:self.containerId];
  33. }
  34. /**
  35. * fix for #877, #878
  36. */
  37. -(void)onJsReload {
  38. [self cleanReactLeftovers];
  39. }
  40. /**
  41. * fix for #880
  42. */
  43. -(void)dealloc {
  44. [self cleanReactLeftovers];
  45. }
  46. -(void)cleanReactLeftovers {
  47. [[NSNotificationCenter defaultCenter] removeObserver:self];
  48. [[NSNotificationCenter defaultCenter] removeObserver:self.view];
  49. self.view = nil;
  50. }
  51. @end