123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- #import "RNNEventEmitter.h"
- #import "RNNUtils.h"
-
- @implementation RNNEventEmitter {
- NSInteger _appLaunchedListenerCount;
- BOOL _appLaunchedEventDeferred;
- }
-
- RCT_EXPORT_MODULE();
-
- static NSString* const AppLaunched = @"RNN.AppLaunched";
- static NSString* const CommandCompleted = @"RNN.CommandCompleted";
- static NSString* const BottomTabSelected = @"RNN.BottomTabSelected";
- static NSString* const ComponentDidAppear = @"RNN.ComponentDidAppear";
- static NSString* const ComponentDidDisappear = @"RNN.ComponentDidDisappear";
- static NSString* const NavigationButtonPressed = @"RNN.NavigationButtonPressed";
- static NSString* const ModalDismissed = @"RNN.ModalDismissed";
- static NSString* const SearchBarUpdated = @"RNN.SearchBarUpdated";
- static NSString* const SearchBarCancelPressed = @"RNN.SearchBarCancelPressed";
- static NSString* const PreviewCompleted = @"RNN.PreviewCompleted";
- static NSString* const ScreenPopped = @"RNN.ScreenPopped";
-
- - (NSArray<NSString *> *)supportedEvents {
- return @[AppLaunched,
- CommandCompleted,
- BottomTabSelected,
- ComponentDidAppear,
- ComponentDidDisappear,
- NavigationButtonPressed,
- ModalDismissed,
- SearchBarUpdated,
- SearchBarCancelPressed,
- PreviewCompleted,
- ScreenPopped];
- }
-
- # pragma mark public
-
- - (void)sendOnAppLaunched {
- if (_appLaunchedListenerCount > 0) {
- [self send:AppLaunched body:nil];
- } else {
- _appLaunchedEventDeferred = TRUE;
- }
- }
-
- - (void)sendComponentDidAppear:(NSString *)componentId componentName:(NSString *)componentName {
- [self send:ComponentDidAppear body:@{
- @"componentId":componentId,
- @"componentName": componentName
- }];
- }
-
- - (void)sendComponentDidDisappear:(NSString *)componentId componentName:(NSString *)componentName{
- [self send:ComponentDidDisappear body:@{
- @"componentId":componentId,
- @"componentName": componentName
- }];
- }
-
- - (void)sendOnNavigationButtonPressed:(NSString *)componentId buttonId:(NSString*)buttonId {
- [self send:NavigationButtonPressed body:@{
- @"componentId": componentId,
- @"buttonId": buttonId
- }];
- }
-
- - (void)sendBottomTabSelected:(NSNumber *)selectedTabIndex unselected:(NSNumber*)unselectedTabIndex {
- [self send:BottomTabSelected body:@{
- @"selectedTabIndex": selectedTabIndex,
- @"unselectedTabIndex": unselectedTabIndex
- }];
- }
-
- - (void)sendOnNavigationCommandCompletion:(NSString *)commandName commandId:(NSString *)commandId params:(NSDictionary*)params {
- [self send:CommandCompleted body:@{
- @"commandId":commandId,
- @"commandName":commandName,
- @"params": params,
- @"completionTime": [RNNUtils getCurrentTimestamp]
- }];
- }
-
- - (void)sendOnSearchBarUpdated:(NSString *)componentId
- text:(NSString*)text
- isFocused:(BOOL)isFocused {
- [self send:SearchBarUpdated body:@{
- @"componentId": componentId,
- @"text": text,
- @"isFocused": @(isFocused)
- }];
- }
-
- - (void)sendOnSearchBarCancelPressed:(NSString *)componentId {
- [self send:SearchBarCancelPressed body:@{
- @"componentId": componentId
- }];
- }
-
- - (void)sendOnPreviewCompleted:(NSString *)componentId previewComponentId:(NSString *)previewComponentId {
- [self send:PreviewCompleted body:@{
- @"componentId": componentId,
- @"previewComponentId": previewComponentId
- }];
- }
-
- - (void)sendModalsDismissedEvent:(NSString *)componentId numberOfModalsDismissed:(NSNumber *)modalsDismissed {
- [self send:ModalDismissed body:@{
- @"componentId": componentId,
- @"modalsDismissed": modalsDismissed
- }];
- }
-
- - (void)sendScreenPoppedEvent:(NSString *)componentId {
- [self send:ScreenPopped body:@{
- @"componentId": componentId
- }];
- }
-
- - (void)addListener:(NSString *)eventName {
- [super addListener:eventName];
- if ([eventName isEqualToString:AppLaunched]) {
- _appLaunchedListenerCount++;
- if (_appLaunchedEventDeferred) {
- _appLaunchedEventDeferred = FALSE;
- [self sendOnAppLaunched];
- }
- }
- }
-
- # pragma mark private
-
- - (void)send:(NSString *)eventName body:(id)body {
- if (self.bridge == nil) {
- return;
- }
- [self sendEventWithName:eventName body:body];
- }
-
- @end
|