Support bridgeless in RCTEventDispatcher

Summary:
This ties the stack together, utilizes new TM functionality to avoid using the bridge in `RCTEventDispatcher`.

Changelog: [Internal]

Differential Revision: D22962320

fbshipit-source-id: de4e001a4a6ce232c37d7feed1e0c0d1d70a80f8
This commit is contained in:
Peter Argany
2020-08-07 11:55:51 -07:00
committed by Facebook GitHub Bot
parent c494d590fb
commit ffdfbbec08
2 changed files with 37 additions and 15 deletions
+2 -1
View File
@@ -8,6 +8,7 @@
#import <UIKit/UIKit.h>
#import <React/RCTBridge.h>
#import <React/RCTJSInvokerModule.h>
typedef NS_ENUM(NSInteger, RCTTextEventType) {
RCTTextEventTypeFocus,
@@ -79,7 +80,7 @@ RCT_EXTERN NSString *RCTNormalizeInputEventName(NSString *eventName);
* This class wraps the -[RCTBridge enqueueJSCall:args:] method, and
* provides some convenience methods for generating event calls.
*/
@interface RCTEventDispatcher : NSObject <RCTBridgeModule>
@interface RCTEventDispatcher : NSObject <RCTBridgeModule, RCTJSDispatcherModule, RCTJSInvokerModule>
/**
* Deprecated, do not use.
+35 -14
View File
@@ -48,6 +48,9 @@ static uint16_t RCTUniqueCoalescingKeyGenerator = 0;
}
@synthesize bridge = _bridge;
@synthesize dispatchToJSThread = _dispatchToJSThread;
@synthesize invokeJS = _invokeJS;
@synthesize invokeJSWithModuleDotMethod = _invokeJSWithModuleDotMethod;
RCT_EXPORT_MODULE()
@@ -64,18 +67,26 @@ RCT_EXPORT_MODULE()
- (void)sendAppEventWithName:(NSString *)name body:(id)body
{
[_bridge enqueueJSCall:@"RCTNativeAppEventEmitter"
method:@"emit"
args:body ? @[ name, body ] : @[ name ]
completion:NULL];
if (_bridge) {
[_bridge enqueueJSCall:@"RCTNativeAppEventEmitter"
method:@"emit"
args:body ? @[ name, body ] : @[ name ]
completion:NULL];
} else {
_invokeJS(@"RCTNativeAppEventEmitter", @"emit", body ? @[ name, body ] : @[ name ]);
}
}
- (void)sendDeviceEventWithName:(NSString *)name body:(id)body
{
[_bridge enqueueJSCall:@"RCTDeviceEventEmitter"
method:@"emit"
args:body ? @[ name, body ] : @[ name ]
completion:NULL];
if (_bridge) {
[_bridge enqueueJSCall:@"RCTDeviceEventEmitter"
method:@"emit"
args:body ? @[ name, body ] : @[ name ]
completion:NULL];
} else {
_invokeJS(@"RCTDeviceEventEmitter", @"emit", body ? @[ name, body ] : @[ name ]);
}
}
- (void)sendTextEventWithType:(RCTTextEventType)type
@@ -162,11 +173,17 @@ RCT_EXPORT_MODULE()
[_eventQueueLock unlock];
if (scheduleEventsDispatch) {
[_bridge
dispatchBlock:^{
[self flushEventsQueue];
}
queue:RCTJSThread];
if (_bridge) {
[_bridge
dispatchBlock:^{
[self flushEventsQueue];
}
queue:RCTJSThread];
} else {
_dispatchToJSThread(^{
[self flushEventsQueue];
});
}
}
}
@@ -186,7 +203,11 @@ RCT_EXPORT_MODULE()
- (void)dispatchEvent:(id<RCTEvent>)event
{
[_bridge enqueueJSCall:[[event class] moduleDotMethod] args:[event arguments]];
if (_bridge) {
[_bridge enqueueJSCall:[[event class] moduleDotMethod] args:[event arguments]];
} else {
_invokeJSWithModuleDotMethod([[event class] moduleDotMethod], [event arguments]);
}
}
- (dispatch_queue_t)methodQueue