react-native-navigation的迁移库

RNNRootViewController.m 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #import "RNNRootViewController.h"
  2. @interface RNNRootViewController()
  3. @property NSString* containerId;
  4. @property NSString* containerName;
  5. @property RNNEventEmitter *eventEmitter;
  6. @end
  7. @implementation RNNRootViewController
  8. -(instancetype)initWithNode:(RNNLayoutNode*)node rootViewCreator:(id<RNNRootViewCreator>)creator eventEmitter:(RNNEventEmitter*)eventEmitter {
  9. self = [super init];
  10. self.containerId = node.nodeId;
  11. self.containerName = node.data[@"name"];
  12. self.eventEmitter = eventEmitter;
  13. self.view = [creator createRootView:self.containerName rootViewId:self.containerId];
  14. [[NSNotificationCenter defaultCenter] addObserver:self
  15. selector:@selector(onJsReload)
  16. name:RCTJavaScriptWillStartLoadingNotification
  17. object:nil];
  18. return self;
  19. }
  20. -(void)viewDidAppear:(BOOL)animated {
  21. [super viewDidAppear:animated];
  22. [self.eventEmitter sendContainerStart:self.containerId];
  23. }
  24. -(void)viewDidDisappear:(BOOL)animated {
  25. [super viewDidDisappear:animated];
  26. [self.eventEmitter sendContainerStop:self.containerId];
  27. }
  28. /**
  29. * fix for #877
  30. */
  31. -(void)onJsReload {
  32. [[NSNotificationCenter defaultCenter] removeObserver:self];
  33. [[NSNotificationCenter defaultCenter] removeObserver:self.view];
  34. self.view = nil;
  35. }
  36. @end