From 7225daf98d5b1cf71a90a491275077e454e7e4db Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Mon, 10 Jun 2019 18:37:57 -0700 Subject: [PATCH] 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 --- .../platform/ios/RCTTurboModuleManager.mm | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm index 91fdbc9b329..83da4c8b50b 100644 --- a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm +++ b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm @@ -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. *