react-native-navigation的迁移库

RNNRootViewController.m 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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, #878
  30. */
  31. -(void)onJsReload {
  32. [self cleanReactLeftovers];
  33. }
  34. /**
  35. * fix for #880
  36. */
  37. -(void)dealloc {
  38. [self cleanReactLeftovers];
  39. }
  40. -(void)cleanReactLeftovers {
  41. [[NSNotificationCenter defaultCenter] removeObserver:self];
  42. [[NSNotificationCenter defaultCenter] removeObserver:self.view];
  43. self.view = nil;
  44. }
  45. @end