@@ -219,20 +219,22 @@ @implementation RCTModuleMethod
219
219
220
220
static Class _globalExecutorClass;
221
221
222
- NS_INLINE NSString *RCTStringUpToFirstArgument (NSString *methodName) {
222
+ static NSString *RCTStringUpToFirstArgument (NSString *methodName)
223
+ {
223
224
NSRange colonRange = [methodName rangeOfString: @" :" ];
224
225
if (colonRange.length ) {
225
226
methodName = [methodName substringToIndex: colonRange.location];
226
227
}
227
228
return methodName;
228
229
}
229
230
230
- - (instancetype )initWithMethodName : (NSString *)methodName
231
- JSMethodName : (NSString *)JSMethodName
231
+ - (instancetype )initWithReactMethodName : (NSString *)reactMethodName
232
+ objCMethodName : (NSString *)objCMethodName
233
+ JSMethodName : (NSString *)JSMethodName
232
234
{
233
235
if ((self = [super init ])) {
234
- _methodName = methodName ;
235
- NSArray *parts = [[methodName substringWithRange: (NSRange ){2 , methodName .length - 3 }] componentsSeparatedByString: @" " ];
236
+ _methodName = reactMethodName ;
237
+ NSArray *parts = [[reactMethodName substringWithRange: (NSRange ){2 , reactMethodName .length - 3 }] componentsSeparatedByString: @" " ];
236
238
237
239
// Parse class and method
238
240
_moduleClassName = parts[0 ];
@@ -246,7 +248,7 @@ - (instancetype)initWithMethodName:(NSString *)methodName
246
248
// New format
247
249
NSString *selectorString = [parts[1 ] substringFromIndex: 14 ];
248
250
_selector = NSSelectorFromString (selectorString);
249
- _JSMethodName = RCTStringUpToFirstArgument (selectorString);
251
+ _JSMethodName = JSMethodName ?: RCTStringUpToFirstArgument (selectorString);
250
252
251
253
static NSRegularExpression *regExp;
252
254
if (!regExp) {
@@ -258,8 +260,8 @@ - (instancetype)initWithMethodName:(NSString *)methodName
258
260
}
259
261
260
262
argumentNames = [NSMutableArray array ];
261
- [regExp enumerateMatchesInString: JSMethodName options: 0 range: NSMakeRange (0 , JSMethodName .length) usingBlock: ^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
262
- NSString *argumentName = [JSMethodName substringWithRange: [result rangeAtIndex: 1 ]];
263
+ [regExp enumerateMatchesInString: objCMethodName options: 0 range: NSMakeRange (0 , objCMethodName .length) usingBlock: ^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
264
+ NSString *argumentName = [objCMethodName substringWithRange: [result rangeAtIndex: 1 ]];
263
265
[(NSMutableArray *)argumentNames addObject: argumentName];
264
266
}];
265
267
} else {
@@ -270,14 +272,15 @@ - (instancetype)initWithMethodName:(NSString *)methodName
270
272
}
271
273
272
274
// Extract class and method details
273
- _isClassMethod = [methodName characterAtIndex: 0 ] == ' +' ;
275
+ _isClassMethod = [reactMethodName characterAtIndex: 0 ] == ' +' ;
274
276
_moduleClass = NSClassFromString (_moduleClassName);
275
277
276
278
#if DEBUG
279
+
277
280
// Sanity check
278
281
RCTAssert ([_moduleClass conformsToProtocol: @protocol (RCTBridgeModule)],
279
282
@" You are attempting to export the method %@ , but %@ does not \
280
- conform to the RCTBridgeModule Protocol" , methodName , _moduleClassName);
283
+ conform to the RCTBridgeModule Protocol" , objCMethodName , _moduleClassName);
281
284
#endif
282
285
283
286
// Get method signature
@@ -290,26 +293,26 @@ - (instancetype)initWithMethodName:(NSString *)methodName
290
293
NSMutableArray *argumentBlocks = [[NSMutableArray alloc ] initWithCapacity: numberOfArguments - 2 ];
291
294
292
295
#define RCT_ARG_BLOCK (_logic ) \
293
- [argumentBlocks addObject: ^(RCTBridge *bridge, NSInvocation *invocation, NSUInteger index , id json) { \
294
- _logic \
295
- [invocation setArgument: &value atIndex: index ]; \
296
- }]; \
296
+ [argumentBlocks addObject: ^(RCTBridge *bridge, NSInvocation *invocation, NSUInteger index , id json) { \
297
+ _logic \
298
+ [invocation setArgument: &value atIndex: index ]; \
299
+ }]; \
297
300
298
301
void (^addBlockArgument)(void ) = ^{
299
302
RCT_ARG_BLOCK (
300
- if (json && ![json isKindOfClass: [NSNumber class ]]) {
301
- RCTLogError (@" Argument %tu (%@ ) of %@ .%@ should be a number" , index ,
302
- json, RCTBridgeModuleNameForClass (_moduleClass), _JSMethodName);
303
- return ;
304
- }
305
-
306
- // Marked as autoreleasing, because NSInvocation doesn't retain arguments
307
- __autoreleasing id value = (json ? ^(NSArray *args) {
308
- [bridge _invokeAndProcessModule: @" BatchedBridge"
309
- method: @" invokeCallbackAndReturnFlushedQueue"
310
- arguments: @[json, args]];
311
- } : ^(NSArray *unused) {});
312
- )
303
+ if (json && ![json isKindOfClass: [NSNumber class ]]) {
304
+ RCTLogError (@" Argument %tu (%@ ) of %@ .%@ should be a number" , index ,
305
+ json, RCTBridgeModuleNameForClass (_moduleClass), _JSMethodName);
306
+ return ;
307
+ }
308
+
309
+ // Marked as autoreleasing, because NSInvocation doesn't retain arguments
310
+ __autoreleasing id value = (json ? ^(NSArray *args) {
311
+ [bridge _invokeAndProcessModule: @" BatchedBridge"
312
+ method: @" invokeCallbackAndReturnFlushedQueue"
313
+ arguments: @[json, args]];
314
+ } : ^(NSArray *unused) {});
315
+ )
313
316
};
314
317
315
318
void (^defaultCase)(const char *) = ^(const char *argumentType) {
@@ -333,11 +336,11 @@ - (instancetype)initWithMethodName:(NSString *)methodName
333
336
switch (argumentType[0 ]) {
334
337
335
338
#define RCT_CONVERT_CASE (_value, _type ) \
336
- case _value: { \
337
- _type (*convert)(id , SEL , id ) = (typeof (convert))[RCTConvert methodForSelector: selector]; \
338
- RCT_ARG_BLOCK ( _type value = convert ([RCTConvert class ], selector, json); ) \
339
- break ; \
340
- }
339
+ case _value: { \
340
+ _type (*convert)(id , SEL , id ) = (typeof (convert))[RCTConvert methodForSelector: selector]; \
341
+ RCT_ARG_BLOCK ( _type value = convert ([RCTConvert class ], selector, json); ) \
342
+ break ; \
343
+ }
341
344
342
345
RCT_CONVERT_CASE (' :' , SEL )
343
346
RCT_CONVERT_CASE (' *' , const char *)
@@ -371,33 +374,33 @@ - (instancetype)initWithMethodName:(NSString *)methodName
371
374
switch (argumentType[0 ]) {
372
375
373
376
#define RCT_CASE (_value, _class, _logic ) \
374
- case _value: { \
375
- RCT_ARG_BLOCK ( \
376
- if (json && ![json isKindOfClass: [_class class ]]) { \
377
- RCTLogError (@" Argument %tu (%@ ) of %@ .%@ should be of type %@ " , index , \
378
- json, RCTBridgeModuleNameForClass (_moduleClass), _JSMethodName, [_class class ]); \
379
- return ; \
380
- } \
381
- _logic \
382
- ) \
383
- break ; \
384
- }
377
+ case _value: { \
378
+ RCT_ARG_BLOCK ( \
379
+ if (json && ![json isKindOfClass: [_class class ]]) { \
380
+ RCTLogError (@" Argument %tu (%@ ) of %@ .%@ should be of type %@ " , index , \
381
+ json, RCTBridgeModuleNameForClass (_moduleClass), _JSMethodName, [_class class ]); \
382
+ return ; \
383
+ } \
384
+ _logic \
385
+ ) \
386
+ break ; \
387
+ }
385
388
386
389
RCT_CASE (' :' , NSString , SEL value = NSSelectorFromString (json); )
387
390
RCT_CASE (' *' , NSString , const char *value = [json UTF8String ]; )
388
391
389
392
#define RCT_SIMPLE_CASE (_value, _type, _selector ) \
390
- case _value: { \
391
- RCT_ARG_BLOCK ( \
392
- if (json && ![json respondsToSelector: @selector (_selector )]) { \
393
- RCTLogError (@" Argument %tu (%@ ) of %@ .%@ does not respond to selector: %@ " , \
394
- index , json, RCTBridgeModuleNameForClass (_moduleClass), _JSMethodName, @#_selector); \
395
- return ; \
396
- } \
397
- _type value = [json _selector ]; \
398
- ) \
399
- break ; \
400
- }
393
+ case _value: { \
394
+ RCT_ARG_BLOCK ( \
395
+ if (json && ![json respondsToSelector: @selector (_selector )]) { \
396
+ RCTLogError (@" Argument %tu (%@ ) of %@ .%@ does not respond to selector: %@ " , \
397
+ index , json, RCTBridgeModuleNameForClass (_moduleClass), _JSMethodName, @#_selector); \
398
+ return ; \
399
+ } \
400
+ _type value = [json _selector ]; \
401
+ ) \
402
+ break ; \
403
+ }
401
404
402
405
RCT_SIMPLE_CASE (' c' , char , charValue)
403
406
RCT_SIMPLE_CASE (' C' , unsigned char , unsignedCharValue)
@@ -432,6 +435,7 @@ - (void)invokeWithBridge:(RCTBridge *)bridge
432
435
{
433
436
434
437
#if DEBUG
438
+
435
439
// Sanity check
436
440
RCTAssert ([module class ] == _moduleClass, @" Attempted to invoke method \
437
441
%@ on a module of class %@ " , _methodName, [module class ]);
@@ -496,15 +500,24 @@ - (NSString *)description
496
500
497
501
for (RCTHeaderValue addr = section->offset ;
498
502
addr < section->offset + section->size ;
499
- addr += sizeof (const char **) * 2 ) {
503
+ addr += sizeof (const char **) * 3 ) {
500
504
501
505
// Get data entry
502
506
const char **entries = (const char **)(mach_header + addr);
503
507
504
508
// Create method
505
- RCTModuleMethod *moduleMethod =
506
- [[RCTModuleMethod alloc ] initWithMethodName: @(entries[0 ])
507
- JSMethodName: strlen (entries[1 ]) ? @(entries[1 ]) : nil ];
509
+ RCTModuleMethod *moduleMethod;
510
+ if (entries[2 ] == NULL ) {
511
+
512
+ // Legacy support for RCT_EXPORT()
513
+ moduleMethod = [[RCTModuleMethod alloc ] initWithReactMethodName: @(entries[0 ])
514
+ objCMethodName: @(entries[0 ])
515
+ JSMethodName: strlen (entries[1 ]) ? @(entries[1 ]) : nil ];
516
+ } else {
517
+ moduleMethod = [[RCTModuleMethod alloc ] initWithReactMethodName: @(entries[0 ])
518
+ objCMethodName: strlen (entries[1 ]) ? @(entries[1 ]) : nil
519
+ JSMethodName: strlen (entries[2 ]) ? @(entries[2 ]) : nil ];
520
+ }
508
521
509
522
// Cache method
510
523
NSArray *methods = methodsByModuleClassName[moduleMethod.moduleClassName];
@@ -560,15 +573,15 @@ - (NSString *)description
560
573
NSMutableDictionary *methodsByName = [NSMutableDictionary dictionaryWithCapacity: methods.count];
561
574
[methods enumerateObjectsUsingBlock: ^(RCTModuleMethod *method, NSUInteger methodID, BOOL *_stop) {
562
575
methodsByName[method.JSMethodName] = @{
563
- @" methodID" : @(methodID),
564
- @" type" : @" remote" ,
565
- };
576
+ @" methodID" : @(methodID),
577
+ @" type" : @" remote" ,
578
+ };
566
579
}];
567
580
568
581
NSDictionary *module = @{
569
- @" moduleID" : @(moduleID),
570
- @" methods" : methodsByName
571
- };
582
+ @" moduleID" : @(moduleID),
583
+ @" methods" : methodsByName
584
+ };
572
585
573
586
remoteModuleConfigByClassName[NSStringFromClass (moduleClass)] = module;
574
587
}];
@@ -639,9 +652,9 @@ - (NSString *)description
639
652
NSDictionary *module = localModules[moduleName];
640
653
if (!module) {
641
654
module = @{
642
- @" moduleID" : @(localModules.count ),
643
- @" methods" : [[NSMutableDictionary alloc ] init ]
644
- };
655
+ @" moduleID" : @(localModules.count ),
656
+ @" methods" : [[NSMutableDictionary alloc ] init ]
657
+ };
645
658
localModules[moduleName] = module;
646
659
}
647
660
@@ -650,9 +663,9 @@ - (NSString *)description
650
663
NSMutableDictionary *methods = module[@" methods" ];
651
664
if (!methods[methodName]) {
652
665
methods[methodName] = @{
653
- @" methodID" : @(methods.count ),
654
- @" type" : @" local"
655
- };
666
+ @" methodID" : @(methods.count ),
667
+ @" type" : @" local"
668
+ };
656
669
}
657
670
658
671
// Add module and method lookup
@@ -741,9 +754,9 @@ - (void)setUp
741
754
742
755
// Inject module data into JS context
743
756
NSString *configJSON = RCTJSONStringify (@{
744
- @" remoteModuleConfig" : RCTRemoteModulesConfig (_modulesByName),
745
- @" localModulesConfig" : RCTLocalModulesConfig ()
746
- }, NULL );
757
+ @" remoteModuleConfig" : RCTRemoteModulesConfig (_modulesByName),
758
+ @" localModulesConfig" : RCTLocalModulesConfig ()
759
+ }, NULL );
747
760
dispatch_semaphore_t semaphore = dispatch_semaphore_create (0 );
748
761
[_javaScriptExecutor injectJSONText: configJSON
749
762
asGlobalObjectNamed: @" __fbBatchedBridgeConfig" callback: ^(id err) {
0 commit comments