diff --git a/lib/ios/RNNBottomTabsController.h b/lib/ios/RNNBottomTabsController.h index dfde621bf5..613b63e8a0 100644 --- a/lib/ios/RNNBottomTabsController.h +++ b/lib/ios/RNNBottomTabsController.h @@ -1,10 +1,10 @@ +#import #import "BottomTabPresenter.h" #import "BottomTabsBaseAttacher.h" #import "RNNBottomTabsPresenter.h" #import "RNNDotIndicatorPresenter.h" #import "RNNEventEmitter.h" #import "UIViewController+LayoutProtocol.h" -#import @interface RNNBottomTabsController : UITabBarController diff --git a/lib/ios/RNNBridgeEventEmitter.h b/lib/ios/RNNBridgeEventEmitter.h index d91fbd4398..a844a624e4 100644 --- a/lib/ios/RNNBridgeEventEmitter.h +++ b/lib/ios/RNNBridgeEventEmitter.h @@ -1,4 +1,6 @@ #import "RNNEventEmitter.h" +#import -@interface RNNBridgeEventEmitter : RNNEventEmitter +@interface RNNBridgeEventEmitter : RNNEventEmitter @end + diff --git a/lib/ios/RNNBridgeEventEmitter.mm b/lib/ios/RNNBridgeEventEmitter.mm index bf153caecb..db5eca5494 100644 --- a/lib/ios/RNNBridgeEventEmitter.mm +++ b/lib/ios/RNNBridgeEventEmitter.mm @@ -1,5 +1,6 @@ #import "RNNBridgeEventEmitter.h" -@implementation RNNBridgeEventEmitter {} +@implementation RNNBridgeEventEmitter +RCT_EXPORT_MODULE() @end diff --git a/lib/ios/RNNEmitterConstants.h b/lib/ios/RNNEmitterConstants.h new file mode 100644 index 0000000000..beacd75789 --- /dev/null +++ b/lib/ios/RNNEmitterConstants.h @@ -0,0 +1,16 @@ +typedef NSString * EmitterEvents NS_STRING_ENUM; +extern EmitterEvents const AppLaunched; +extern EmitterEvents const CommandCompleted; +extern EmitterEvents const BottomTabSelected; +extern EmitterEvents const BottomTabLongPressed; +extern EmitterEvents const ComponentWillAppear; +extern EmitterEvents const ComponentDidAppear; +extern EmitterEvents const ComponentDidDisappear; +extern EmitterEvents const NavigationButtonPressed; +extern EmitterEvents const ModalDismissed; +extern EmitterEvents const ModalAttemptedToDismiss; +extern EmitterEvents const SearchBarUpdated; +extern EmitterEvents const SearchBarCancelPressed; +extern EmitterEvents const PreviewCompleted; +extern EmitterEvents const ScreenPopped; +extern EmitterEvents const BottomTabPressed; diff --git a/lib/ios/RNNEmitterConstants.mm b/lib/ios/RNNEmitterConstants.mm new file mode 100644 index 0000000000..f1ba2a57d3 --- /dev/null +++ b/lib/ios/RNNEmitterConstants.mm @@ -0,0 +1,18 @@ +#import "RNNEmitterConstants.h" + +EmitterEvents const AppLaunched = @"RNN.AppLaunched"; +EmitterEvents const CommandCompleted = @"RNN.CommandCompleted"; +EmitterEvents const BottomTabSelected = @"RNN.BottomTabSelected"; +EmitterEvents const BottomTabLongPressed = @"RNN.BottomTabLongPressed"; +EmitterEvents const ComponentWillAppear = @"RNN.ComponentWillAppear"; +EmitterEvents const ComponentDidAppear = @"RNN.ComponentDidAppear"; +EmitterEvents const ComponentDidDisappear = @"RNN.ComponentDidDisappear"; +EmitterEvents const NavigationButtonPressed = @"RNN.NavigationButtonPressed"; +EmitterEvents const ModalDismissed = @"RNN.ModalDismissed"; +EmitterEvents const ModalAttemptedToDismiss = @"RNN.ModalAttemptedToDismiss"; +EmitterEvents const SearchBarUpdated = @"RNN.SearchBarUpdated"; +EmitterEvents const SearchBarCancelPressed = @"RNN.SearchBarCancelPressed"; +EmitterEvents const PreviewCompleted = @"RNN.PreviewCompleted"; +EmitterEvents const ScreenPopped = @"RNN.ScreenPopped"; +EmitterEvents const BottomTabPressed = @"RNN.BottomTabPressed"; + diff --git a/lib/ios/RNNEventEmitter.h b/lib/ios/RNNEventEmitter.h index 2008014e6a..d974be2464 100644 --- a/lib/ios/RNNEventEmitter.h +++ b/lib/ios/RNNEventEmitter.h @@ -1,13 +1,19 @@ #import +#ifndef RCT_NEW_ARCH_ENABLED #import +#endif +#ifdef RCT_NEW_ARCH_ENABLED @class RCTHost; -@class RCTBridge; - @interface RNNEventEmitter : NSObject +#else +@interface RNNEventEmitter : RCTEventEmitter +#endif +#ifdef RCT_NEW_ARCH_ENABLED - (void)setHost:(RCTHost *)host; @property(nonatomic, strong, readonly) RCTHost *host; +#endif - (void)sendOnAppLaunched; diff --git a/lib/ios/RNNEventEmitter.mm b/lib/ios/RNNEventEmitter.mm index fe03a354ed..fd4b914d9c 100644 --- a/lib/ios/RNNEventEmitter.mm +++ b/lib/ios/RNNEventEmitter.mm @@ -1,22 +1,65 @@ #import "RNNEventEmitter.h" #import "RNNUtils.h" +#import "RNNEmitterConstants.h" + +#ifdef RCT_NEW_ARCH_ENABLED #import "RNNTurboEventEmitter.h" #import +#else + +#endif -@implementation RNNEventEmitter { } +@implementation RNNEventEmitter { +#ifndef RCT_NEW_ARCH_ENABLED + RCTEventEmitter *_emitter; + NSInteger _appLaunchedListenerCount; + BOOL _appLaunchedEventDeferred; +#endif +} +#ifdef RCT_NEW_ARCH_ENABLED - (void)setHost:(RCTHost *)host { if (_host != nil) { return; } _host = host; } - +#else +- (NSArray *)supportedEvents { + return @[ + AppLaunched, CommandCompleted, BottomTabSelected, BottomTabLongPressed, BottomTabPressed, + ComponentWillAppear, ComponentDidAppear, ComponentDidDisappear, NavigationButtonPressed, + ModalDismissed, SearchBarUpdated, SearchBarCancelPressed, PreviewCompleted, ScreenPopped, + ModalAttemptedToDismiss + ]; +} + +- (void)addListener:(NSString *)eventName { + [super addListener:eventName]; + if ([eventName isEqualToString:AppLaunched]) { + _appLaunchedListenerCount++; + if (_appLaunchedEventDeferred) { + _appLaunchedEventDeferred = FALSE; + [self sendOnAppLaunched]; + } + } +} +#endif #pragma mark public +#ifdef RCT_NEW_ARCH_ENABLED - (void)sendOnAppLaunched { [self send:AppLaunched body:nil]; } +#else +- (void)sendOnAppLaunched { + if (_appLaunchedListenerCount > 0) { + [self send:AppLaunched body:nil]; + } else { + _appLaunchedEventDeferred = TRUE; + } +} +#endif - (void)sendComponentWillAppear:(NSString *)componentId componentName:(NSString *)componentName @@ -119,6 +162,7 @@ - (void)sendScreenPoppedEvent:(NSString *)componentId { #pragma mark private - (void)send:(NSString *)eventName body:(id)body { +#ifdef RCT_NEW_ARCH_ENABLED if (_host == nil) { return; } @@ -129,6 +173,12 @@ - (void)send:(NSString *)eventName body:(id)body { } [_eventEmitter send:eventName body:body]; +#else + if (self.bridge == nil) { + return; + } + [self sendEventWithName:eventName body:body]; +#endif } @end diff --git a/lib/ios/RNNModalManagerEventHandler.h b/lib/ios/RNNModalManagerEventHandler.h index 5d313d9ea7..f0a4cd23b6 100644 --- a/lib/ios/RNNModalManagerEventHandler.h +++ b/lib/ios/RNNModalManagerEventHandler.h @@ -1,5 +1,6 @@ -#import "RNNEventEmitter.h" #import +#import +#import "RNNEventEmitter.h" @interface RNNModalManagerEventHandler : NSObject diff --git a/lib/ios/RNNReactRootViewCreator.h b/lib/ios/RNNReactRootViewCreator.h index d2bc876398..a4a8e960bf 100644 --- a/lib/ios/RNNReactRootViewCreator.h +++ b/lib/ios/RNNReactRootViewCreator.h @@ -1,6 +1,6 @@ +#import #import "RNNComponentViewCreator.h" #import "RNNEventEmitter.h" -#import #import @interface RNNReactRootViewCreator : NSObject diff --git a/lib/ios/RNNViewControllerFactory.h b/lib/ios/RNNViewControllerFactory.h index f157c5fb16..a97f404fe1 100644 --- a/lib/ios/RNNViewControllerFactory.h +++ b/lib/ios/RNNViewControllerFactory.h @@ -1,3 +1,5 @@ +#import +#import #import "BottomTabsAttachModeFactory.h" #import "RNNComponentViewCreator.h" @@ -5,8 +7,6 @@ #import "RNNExternalComponentStore.h" #import "RNNNavigationOptions.h" #import "RNNReactComponentRegistry.h" -#import -#import @interface RNNViewControllerFactory : NSObject diff --git a/lib/ios/StackControllerDelegate.h b/lib/ios/StackControllerDelegate.h index dff5a31ba3..e7b1ab9105 100644 --- a/lib/ios/StackControllerDelegate.h +++ b/lib/ios/StackControllerDelegate.h @@ -1,10 +1,11 @@ +#import +#import + #ifdef RCT_NEW_ARCH_ENABLED #import "RNNEventEmitter.h" #else #import "RNNEventEmitter.h" #endif -#import -#import @class RCTHost; diff --git a/lib/ios/TurboModules/RNNTurboEventEmitter.h b/lib/ios/TurboModules/RNNTurboEventEmitter.h index 56d1fb7e5c..5870d054f6 100644 --- a/lib/ios/TurboModules/RNNTurboEventEmitter.h +++ b/lib/ios/TurboModules/RNNTurboEventEmitter.h @@ -1,25 +1,7 @@ #ifdef RCT_NEW_ARCH_ENABLED -#import "RNNEventEmitter.h" +#import #import -typedef NSString * EmitterEvents NS_STRING_ENUM; - -extern EmitterEvents const AppLaunched; -extern EmitterEvents const CommandCompleted; -extern EmitterEvents const BottomTabSelected; -extern EmitterEvents const BottomTabLongPressed; -extern EmitterEvents const ComponentWillAppear; -extern EmitterEvents const ComponentDidAppear; -extern EmitterEvents const ComponentDidDisappear; -extern EmitterEvents const NavigationButtonPressed; -extern EmitterEvents const ModalDismissed; -extern EmitterEvents const ModalAttemptedToDismiss; -extern EmitterEvents const SearchBarUpdated; -extern EmitterEvents const SearchBarCancelPressed; -extern EmitterEvents const PreviewCompleted; -extern EmitterEvents const ScreenPopped; -extern EmitterEvents const BottomTabPressed; - @interface RNNTurboEventEmitter : RCTEventEmitter - (void)send:(NSString *)eventName body:(id)body; @end diff --git a/lib/ios/TurboModules/RNNTurboEventEmitter.mm b/lib/ios/TurboModules/RNNTurboEventEmitter.mm index 0ea7a55612..5e303f22f2 100644 --- a/lib/ios/TurboModules/RNNTurboEventEmitter.mm +++ b/lib/ios/TurboModules/RNNTurboEventEmitter.mm @@ -1,24 +1,8 @@ #ifdef RCT_NEW_ARCH_ENABLED #import "RNNTurboEventEmitter.h" - +#import "RNNEmitterConstants.h" #import "RNNUtils.h" -EmitterEvents const AppLaunched = @"RNN.AppLaunched"; -EmitterEvents const CommandCompleted = @"RNN.CommandCompleted"; -EmitterEvents const BottomTabSelected = @"RNN.BottomTabSelected"; -EmitterEvents const BottomTabLongPressed = @"RNN.BottomTabLongPressed"; -EmitterEvents const ComponentWillAppear = @"RNN.ComponentWillAppear"; -EmitterEvents const ComponentDidAppear = @"RNN.ComponentDidAppear"; -EmitterEvents const ComponentDidDisappear = @"RNN.ComponentDidDisappear"; -EmitterEvents const NavigationButtonPressed = @"RNN.NavigationButtonPressed"; -EmitterEvents const ModalDismissed = @"RNN.ModalDismissed"; -EmitterEvents const ModalAttemptedToDismiss = @"RNN.ModalAttemptedToDismiss"; -EmitterEvents const SearchBarUpdated = @"RNN.SearchBarUpdated"; -EmitterEvents const SearchBarCancelPressed = @"RNN.SearchBarCancelPressed"; -EmitterEvents const PreviewCompleted = @"RNN.PreviewCompleted"; -EmitterEvents const ScreenPopped = @"RNN.ScreenPopped"; -EmitterEvents const BottomTabPressed = @"RNN.BottomTabPressed"; - @implementation RNNTurboEventEmitter { NSInteger _appLaunchedListenerCount; BOOL _appLaunchedEventDeferred; diff --git a/lib/ios/UIViewController+LayoutProtocol.h b/lib/ios/UIViewController+LayoutProtocol.h index e8f0f818e2..f047b18fd9 100644 --- a/lib/ios/UIViewController+LayoutProtocol.h +++ b/lib/ios/UIViewController+LayoutProtocol.h @@ -1,6 +1,6 @@ +#import #import "RNNEventEmitter.h" #import "RNNLayoutProtocol.h" -#import typedef void (^RNNReactViewReadyCompletionBlock)(void);