react-native-navigation的迁移库

RNNReactView.m 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #import "RNNReactView.h"
  2. #import "RCTHelpers.h"
  3. #import <React/RCTUIManager.h>
  4. @implementation RNNReactView {
  5. BOOL _isAppeared;
  6. }
  7. - (instancetype)initWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties eventEmitter:(RNNEventEmitter *)eventEmitter reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
  8. self = [super initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
  9. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentDidAppear:) name:RCTContentDidAppearNotification object:nil];
  10. _reactViewReadyBlock = reactViewReadyBlock;
  11. _eventEmitter = eventEmitter;
  12. return self;
  13. }
  14. - (void)layoutSubviews {
  15. [super layoutSubviews];
  16. #ifdef DEBUG
  17. [RCTHelpers removeYellowBox:self];
  18. #endif
  19. }
  20. - (void)contentDidAppear:(NSNotification *)notification {
  21. RNNReactView* appearedView = notification.object;
  22. if ([appearedView.appProperties[@"componentId"] isEqual:self.componentId]) {
  23. [self reactViewReady];
  24. }
  25. }
  26. - (void)reactViewReady {
  27. if (_reactViewReadyBlock) {
  28. _reactViewReadyBlock();
  29. _reactViewReadyBlock = nil;
  30. }
  31. [[NSNotificationCenter defaultCenter] removeObserver:self];
  32. }
  33. - (void)componentDidAppear {
  34. if (!_isAppeared) {
  35. [_eventEmitter sendComponentDidAppear:self.componentId componentName:self.moduleName componentType:self.componentType];
  36. }
  37. _isAppeared = YES;
  38. }
  39. - (void)componentDidDisappear {
  40. if (_isAppeared) {
  41. [_eventEmitter sendComponentDidDisappear:self.componentId componentName:self.moduleName componentType:self.componentType];
  42. }
  43. _isAppeared = NO;
  44. }
  45. - (NSString *)componentId {
  46. return self.appProperties[@"componentId"];
  47. }
  48. - (NSString *)componentType {
  49. return ComponentTypeScreen;
  50. }
  51. @end