react-native-navigation的迁移库

RNNRootViewController.m 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. self.navigationItem.title = node.data[@"navigationStyle"][@"title"];
  19. return self;
  20. }
  21. -(void)viewDidAppear:(BOOL)animated {
  22. [super viewDidAppear:animated];
  23. [self.eventEmitter sendContainerStart:self.containerId];
  24. }
  25. -(void)viewDidDisappear:(BOOL)animated {
  26. [super viewDidDisappear:animated];
  27. [self.eventEmitter sendContainerStop:self.containerId];
  28. }
  29. /**
  30. * fix for #877, #878
  31. */
  32. -(void)onJsReload {
  33. [self cleanReactLeftovers];
  34. }
  35. /**
  36. * fix for #880
  37. */
  38. -(void)dealloc {
  39. [self cleanReactLeftovers];
  40. }
  41. -(void)cleanReactLeftovers {
  42. [[NSNotificationCenter defaultCenter] removeObserver:self];
  43. [[NSNotificationCenter defaultCenter] removeObserver:self.view];
  44. self.view = nil;
  45. }
  46. @end