TM iOS: Support @synthesize methodQueue auto queue creation

Summary: Some native modules defined `synthesize methodQueue` which will ask the bridge to create a new serial queue for them. TM system needs to preserve this behavior for backward compatibility. In the future though, this magic shall be removed.

Reviewed By: mdvacca

Differential Revision: D15748198

fbshipit-source-id: 66a4b60a2769ac967a8d3bb00c4c635a68daebbc
This commit is contained in:
Kevin Gozali
2019-06-10 18:41:22 -07:00
committed by Facebook Github Bot
parent 422472e5d9
commit 7225daf98d
@@ -289,6 +289,30 @@ static Class getFallbackClassFromName(const char *name)
}
}
/**
* Some modules need their own queues, but don't provide any, so we need to create it for them.
* These modules typically have the following:
* `@synthesize methodQueue = _methodQueue`
*/
if ([module respondsToSelector:@selector(methodQueue)]) {
dispatch_queue_t methodQueue = [module performSelector:@selector(methodQueue)];
if (!methodQueue) {
NSString *moduleClassName = NSStringFromClass(module.class);
NSString *queueName = [NSString stringWithFormat:@"com.facebook.react.%@Queue", moduleClassName];
methodQueue = dispatch_queue_create(queueName.UTF8String, DISPATCH_QUEUE_SERIAL);
@try {
[(id)module setValue:methodQueue forKey:@"methodQueue"];
} @catch (NSException *exception) {
RCTLogError(
@"TM: %@ is returning nil for its methodQueue, which is not "
"permitted. You must either return a pre-initialized "
"queue, or @synthesize the methodQueue to let the bridge "
"create a queue for you.",
moduleClassName);
}
}
}
/**
* Broadcast that this TurboModule was created.
*