react-native-navigation的迁移库

RNNRootViewController.m 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. @property (nonatomic, strong) RNNNavigationOptions* navigationOptions;
  9. @end
  10. @implementation RNNRootViewController
  11. -(instancetype)initWithName:(NSString*)name withOptions:(RNNNavigationOptions*)options withContainerId:(NSString*)containerId rootViewCreator:(id<RNNRootViewCreator>)creator eventEmitter:(RNNEventEmitter*)eventEmitter {
  12. self = [super init];
  13. self.containerId = containerId;
  14. self.containerName = name;
  15. self.navigationOptions = options;
  16. self.eventEmitter = eventEmitter;
  17. self.view = [creator createRootView:self.containerName rootViewId:self.containerId];
  18. [[NSNotificationCenter defaultCenter] addObserver:self
  19. selector:@selector(onJsReload)
  20. name:RCTJavaScriptWillStartLoadingNotification
  21. object:nil];
  22. return self;
  23. }
  24. - (BOOL)prefersStatusBarHidden {
  25. return [self.navigationOptions.statusBarHidden boolValue]; // || self.navigationController.isNavigationBarHidden;
  26. }
  27. -(void)viewDidAppear:(BOOL)animated {
  28. [super viewDidAppear:animated];
  29. [self.eventEmitter sendContainerStart:self.containerId];
  30. }
  31. -(void)viewDidDisappear:(BOOL)animated {
  32. [super viewDidDisappear:animated];
  33. [self.eventEmitter sendContainerStop:self.containerId];
  34. }
  35. -(void)viewWillAppear:(BOOL)animated{
  36. [super viewWillAppear:animated];
  37. [self.navigationOptions apply:self];
  38. }
  39. /**
  40. * fix for #877, #878
  41. */
  42. -(void)onJsReload {
  43. [self cleanReactLeftovers];
  44. }
  45. /**
  46. * fix for #880
  47. */
  48. -(void)dealloc {
  49. [self cleanReactLeftovers];
  50. }
  51. -(void)cleanReactLeftovers {
  52. [[NSNotificationCenter defaultCenter] removeObserver:self];
  53. [[NSNotificationCenter defaultCenter] removeObserver:self.view];
  54. self.view = nil;
  55. }
  56. @end