react-native-navigation的迁移库

RNNRootViewController.m 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 withOptions:(RNNNavigationOptions*)options withContainerId:(NSString*)containerId rootViewCreator:(id<RNNRootViewCreator>)creator eventEmitter:(RNNEventEmitter*)eventEmitter {
  11. self = [super init];
  12. self.containerId = containerId;
  13. self.containerName = name;
  14. self.navigationOptions = options;
  15. self.eventEmitter = eventEmitter;
  16. self.view = [creator createRootView:self.containerName rootViewId:self.containerId];
  17. [[NSNotificationCenter defaultCenter] addObserver:self
  18. selector:@selector(onJsReload)
  19. name:RCTJavaScriptWillStartLoadingNotification
  20. object:nil];
  21. return self;
  22. }
  23. - (BOOL)prefersStatusBarHidden {
  24. return [self.navigationOptions.statusBarHidden boolValue]; // || 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. -(void)viewWillAppear:(BOOL)animated{
  35. [super viewWillAppear:animated];
  36. [self.navigationOptions apply:self];
  37. }
  38. /**
  39. * fix for #877, #878
  40. */
  41. -(void)onJsReload {
  42. [self cleanReactLeftovers];
  43. }
  44. /**
  45. * fix for #880
  46. */
  47. -(void)dealloc {
  48. [self cleanReactLeftovers];
  49. }
  50. -(void)cleanReactLeftovers {
  51. [[NSNotificationCenter defaultCenter] removeObserver:self];
  52. [[NSNotificationCenter defaultCenter] removeObserver:self.view];
  53. self.view = nil;
  54. }
  55. @end