Saturday, November 21, 2026
HomeiOS Developmentios - Listening to Swift occasions in Javascript; React Native Native Modules

ios – Listening to Swift occasions in Javascript; React Native Native Modules

[ad_1]

It is really described in fairly a element right here.

  1. First you create an Goal-C bridge to catch occasions from Swift.
  2. Then in Goal-C once more, you implement an RCTEventEmitter (may be similar or totally different class) That is the category that can ship occasions to JS. The occasions are despatched utilizing sendEventWithName operate

Here is a really tough sketch:

Step 1: catch Swift occasions

@interface MyBridge() <SomeDelegate>

@finish

@implementation MyBridge

// Here is my delegate operate:
- (void)myDelegateCalled 
     // Obtained an occasion
     // Calling bridge to ship the occasion to JS
     BridgeEventEmitter ship:someData
     ...

Step 2: ship them to JS

// Here is the BridgeEventEmitter:
@interface BridgeEventEmitter : RCTEventEmitter <RCTBridgeModule>
@finish

@implementation BridgeEventEmitter
+ (void)ship:(NSString *)one thing
{
  [self sendEventWithName:@"EventName" body:something];
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments