react-native-navigation的迁移库

RNNRootViewController.m 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. return [self.navigationOptions.statusBarHidden boolValue]; // || self.navigationController.isNavigationBarHidden;
  33. }
  34. -(void)viewDidAppear:(BOOL)animated {
  35. [super viewDidAppear:animated];
  36. [self.eventEmitter sendContainerDidAppear:self.containerId];
  37. }
  38. -(void)viewDidDisappear:(BOOL)animated {
  39. [super viewDidDisappear:animated];
  40. [self.eventEmitter sendContainerDidDisappear:self.containerId];
  41. }
  42. /**
  43. * fix for #877, #878
  44. */
  45. -(void)onJsReload {
  46. [self cleanReactLeftovers];
  47. }
  48. /**
  49. * fix for #880
  50. */
  51. -(void)dealloc {
  52. [self cleanReactLeftovers];
  53. }
  54. -(void)cleanReactLeftovers {
  55. [[NSNotificationCenter defaultCenter] removeObserver:self];
  56. [[NSNotificationCenter defaultCenter] removeObserver:self.view];
  57. self.view = nil;
  58. }
  59. @end