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 containerDidAppear = @"RNN.containerDidAppear";
  9. static NSString* const containerDidDisappear = @"RNN.containerDidDisappear";
  10. static NSString* const onNavigationButtonPressed = @"RNN.navigationButtonPressed";
  11. -(NSArray<NSString *> *)supportedEvents {
  12. return @[onAppLaunched, containerDidAppear, containerDidDisappear, 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)sendContainerDidAppear:(NSString *)containerId {
  23. [self send:containerDidAppear body:containerId];
  24. }
  25. -(void)sendContainerDidDisappear:(NSString *)containerId {
  26. [self send:containerDidDisappear body:containerId];
  27. }
  28. -(void)sendOnNavigationButtonPressed:(NSString *)containerId buttonId:(NSString*)buttonId {
  29. [self send:onNavigationButtonPressed body:@{@"containerId":containerId , @"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