Skip to content

Commit

Permalink
feat(iOS): working bridgeless event emitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadzim Filipovich committed May 2, 2024
1 parent f74e49f commit 23d9bc9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/ios/RNNEventEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#ifdef RCT_NEW_ARCH_ENABLED
<NativeRNNEventEmitterSpec>

- (instancetype)initWithHost:(RCTHost *)host;
- (void)setHost:(RCTHost *)host;

@property(nonatomic, strong, readonly) RCTHost *host;
#endif
Expand Down
8 changes: 4 additions & 4 deletions lib/ios/RNNEventEmitter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ - (void)send:(NSString *)eventName body:(id)body {
return std::make_shared<facebook::react::NativeRNNEventEmitterSpecJSI>(params);
}

- (instancetype)initWithHost:(RCTHost *)host {
if (self = [self init]) {
_host = host;
- (void)setHost:(RCTHost *)host {
if (_host != nil) {
return;
}
return self;
_host = host;
}
#endif

Expand Down
3 changes: 2 additions & 1 deletion lib/ios/Turbomodules/RNNTurboManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ - (instancetype)initWithHost:(RCTHost *)host mainWindow:(UIWindow *)mainWindow {
name:RCTJavaScriptWillStartLoadingNotification
object:nil];

_eventEmitter = [[RNNEventEmitter alloc] initWithHost:_host];
_eventEmitter = [[_host moduleRegistry] moduleForName:"RNNEventEmitter"];
_eventEmitter.host = _host;

RNNModalManagerEventHandler *modalManagerEventHandler =
[[RNNModalManagerEventHandler alloc] initWithEventEmitter:_eventEmitter];
Expand Down
5 changes: 3 additions & 2 deletions lib/src/adapters/NativeRNNEventEmitter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { TurboModule, TurboModuleRegistry, NativeModules } from "react-native";

export interface Spec extends TurboModule {

addListener: (eventType: string) => void;
removeListeners: (count: number) => void;
}

const emitter = TurboModuleRegistry.get<Spec>("RNNEventEmitter") ?? NativeModules.RNNBridgeEventEmitter;
const emitter = TurboModuleRegistry.get<Spec>("RNNEventEmitter") ?? NativeModules.RNNEventEmitter;

export default emitter;

0 comments on commit 23d9bc9

Please sign in to comment.