react-native-navigation的迁移库

RNNEventEmitter.m 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #import "RNNEventEmitter.h"
  2. @implementation RNNEventEmitter {
  3. NSInteger _appLaunchedListenerCount;
  4. BOOL _appLaunchedEventDeferred;
  5. }
  6. RCT_EXPORT_MODULE();
  7. static NSString* const onAppLaunched = @"RNN.appLaunched";
  8. static NSString* const componentDidAppear = @"RNN.componentDidAppear";
  9. static NSString* const componentDidDisappear = @"RNN.componentDidDisappear";
  10. static NSString* const onNavigationButtonPressed = @"RNN.navigationButtonPressed";
  11. -(NSArray<NSString *> *)supportedEvents {
  12. return @[onAppLaunched, componentDidAppear, componentDidDisappear, onNavigationButtonPressed];
  13. }
  14. # pragma mark public
  15. -(void)sendOnAppLaunched {
  16. if (_appLaunchedListenerCount > 0) {
  17. [self send:onAppLaunched body:nil];
  18. } else {
  19. _appLaunchedEventDeferred = TRUE;
  20. }
  21. }
  22. -(void)sendComponentDidAppear:(NSString *)componentId {
  23. [self send:componentDidAppear body:componentId];
  24. }
  25. -(void)sendComponentDidDisappear:(NSString *)componentId {
  26. [self send:componentDidDisappear body:componentId];
  27. }
  28. -(void)sendOnNavigationButtonPressed:(NSString *)componentId buttonId:(NSString*)buttonId {
  29. [self send:onNavigationButtonPressed body:@{@"componentId":componentId , @"buttonId": buttonId }];
  30. }
  31. - (void)addListener:(NSString *)eventName {
  32. [super addListener:eventName];
  33. if ([eventName isEqualToString:onAppLaunched]) {
  34. _appLaunchedListenerCount++;
  35. if (_appLaunchedEventDeferred) {
  36. _appLaunchedEventDeferred = FALSE;
  37. [self sendOnAppLaunched];
  38. }
  39. }
  40. }
  41. # pragma mark private
  42. -(void)send:(NSString *)eventName body:(id)body {
  43. [self sendEventWithName:eventName body:body];
  44. }
  45. @end