@@ -159,7 +159,7 @@ void invokeSync(const std::string &methodName, std::function<void()> &&work) ove
159159
160160bool isTurboModuleClass (Class cls)
161161{
162- return [cls conformsToProtocol: @protocol (RCTTurboModule )];
162+ return [cls conformsToProtocol: @protocol (RCTModule )];
163163}
164164
165165bool isTurboModuleInstance (id module )
@@ -339,18 +339,24 @@ - (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy
339339 /* *
340340 * Step 2: Look for platform-specific modules.
341341 */
342- id <RCTModuleProvider> module = [self _moduleProviderForName: moduleName];
342+ id <RCTModuleProvider> moduleProvider = [self _moduleProviderForName: moduleName];
343343
344344 TurboModulePerfLogger::moduleJSRequireEndingStart (moduleName);
345345
346346 // If we request that a TurboModule be created, its respective ObjC class must exist
347347 // If the class doesn't exist, then _provideObjCModule returns nil
348- if (!module ) {
348+ if (!moduleProvider ) {
349349 return nullptr ;
350350 }
351+
352+ id <RCTModuleProvider> module = nullptr ;
353+ if ([moduleProvider respondsToSelector: @selector (getAppleModule )]) {
354+ module = (id <RCTModuleProvider>)[self _provideObjCModule: moduleName moduleProvider: moduleProvider];
355+ }
356+ id <RCTModuleProvider> moduleOrProvider = module ? module : moduleProvider;
351357
352358 std::shared_ptr<NativeMethodCallInvoker> nativeMethodCallInvoker = nullptr ;
353- dispatch_queue_t methodQueue = (dispatch_queue_t )objc_getAssociatedObject (module , &kAssociatedMethodQueueKey );
359+ dispatch_queue_t methodQueue = (dispatch_queue_t )objc_getAssociatedObject (moduleOrProvider , &kAssociatedMethodQueueKey );
354360 if (methodQueue) {
355361 /* *
356362 * Step 2c: Create and native CallInvoker from the TurboModule's method queue.
@@ -370,11 +376,11 @@ - (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy
370376 * Step 2d: If the moduleClass is a legacy CxxModule, return a TurboCxxModule instance that
371377 * wraps CxxModule.
372378 */
373- Class moduleClass = [module class ];
379+ Class moduleClass = [moduleOrProvider class ];
374380 if ([moduleClass isSubclassOfClass: RCTCxxModule.class ]) {
375381 // Use TurboCxxModule compat class to wrap the CxxModule instance.
376382 // This is only for migration convenience, despite less performant.
377- auto turboModule = std::make_shared<TurboCxxModule>([((RCTCxxModule *)module ) createModule ], _jsInvoker);
383+ auto turboModule = std::make_shared<TurboCxxModule>([((RCTCxxModule *)moduleOrProvider ) createModule ], _jsInvoker);
378384 _turboModuleCache.insert ({moduleName, turboModule});
379385 return turboModule;
380386 }
@@ -385,27 +391,27 @@ - (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy
385391 * Use respondsToSelector: below to infer conformance to @protocol(RCTTurboModule). Using conformsToProtocol: is
386392 * expensive.
387393 */
388- if ([module respondsToSelector: @selector (getTurboModule: )]) {
394+ if ([moduleProvider respondsToSelector: @selector (getTurboModule: )]) {
389395 ObjCTurboModule::InitParams params = {
390396 .moduleName = moduleName,
391- .instance = (id <RCTBridgeModule>)module ,
397+ .instance = (id <RCTBridgeModule>)moduleOrProvider ,
392398 .jsInvoker = _jsInvoker,
393399 .nativeMethodCallInvoker = nativeMethodCallInvoker,
394400 .isSyncModule = methodQueue == RCTJSThread,
395401 .shouldVoidMethodsExecuteSync = (bool )RCTTurboModuleSyncVoidMethodsEnabled (),
396402 };
397403
398- auto turboModule = [(id <RCTTurboModule>)module getTurboModule: params];
404+ auto turboModule = [(id <RCTTurboModule>)moduleProvider getTurboModule: params];
399405 if (turboModule == nullptr ) {
400406 RCTLogError (@" TurboModule \" %@ \" 's getTurboModule: method returned nil." , moduleClass);
401407 }
402408 _turboModuleCache.insert ({moduleName, turboModule});
403409
404- if ([module respondsToSelector: @selector (installJSIBindingsWithRuntime:callInvoker: )]) {
405- [(id <RCTTurboModuleWithJSIBindings>)module installJSIBindingsWithRuntime: *runtime callInvoker: _jsInvoker];
406- } else if ([module respondsToSelector: @selector (installJSIBindingsWithRuntime: )]) {
410+ if ([moduleOrProvider respondsToSelector: @selector (installJSIBindingsWithRuntime:callInvoker: )]) {
411+ [(id <RCTTurboModuleWithJSIBindings>)moduleOrProvider installJSIBindingsWithRuntime: *runtime callInvoker: _jsInvoker];
412+ } else if ([moduleOrProvider respondsToSelector: @selector (installJSIBindingsWithRuntime: )]) {
407413 // Old API without CallInvoker (deprecated)
408- [(id <RCTTurboModuleWithJSIBindings>)module installJSIBindingsWithRuntime: *runtime];
414+ [(id <RCTTurboModuleWithJSIBindings>)moduleOrProvider installJSIBindingsWithRuntime: *runtime];
409415 }
410416 return turboModule;
411417 }
@@ -496,16 +502,16 @@ - (BOOL)_isLegacyModuleClass:(Class)moduleClass
496502 if ([_delegate respondsToSelector: @selector (getModuleProvider: )]) {
497503 moduleProvider = [_delegate getModuleProvider: moduleName];
498504 }
499-
505+
500506 if (RCTTurboModuleInteropEnabled () && ![self _isTurboModule: moduleName] && !moduleProvider) {
501507 return nil ;
502508 }
503-
509+
504510 if (moduleProvider) {
505- if ([moduleProvider conformsToProtocol: @protocol (RCTTurboModule)]) {
506- // moduleProvider is also a TM, we need to initialize objectiveC properties, like the dispatch queue
511+ if ([moduleProvider conformsToProtocol: @protocol (RCTModule)]) {
507512 return (id <RCTModuleProvider>)[self _provideObjCModule: moduleName moduleProvider: moduleProvider];
508513 }
514+
509515 // module is Cxx module
510516 return moduleProvider;
511517 }
@@ -585,7 +591,12 @@ - (ModuleHolder *)_getOrCreateModuleHolder:(const char *)moduleName
585591 /* *
586592 * Step 2a: Resolve platform-specific class.
587593 */
588- Class moduleClass = moduleProvider ? [moduleProvider class ] : [self _getModuleClassFromName: moduleName];
594+ Class moduleClass = moduleProvider ?
595+ ([moduleProvider respondsToSelector: @selector (getAppleModule )] ?
596+ [moduleProvider getAppleModule ] :
597+ [moduleProvider class ]) :
598+ [self _getModuleClassFromName: moduleName];
599+
589600
590601 __block id <RCTBridgeModule> module = nil ;
591602
@@ -640,7 +651,7 @@ - (BOOL)_shouldCreateObjCModule:(Class)moduleClass
640651 return [moduleClass conformsToProtocol: @protocol (RCTBridgeModule)];
641652 }
642653
643- return [moduleClass conformsToProtocol: @protocol (RCTTurboModule )];
654+ return [moduleClass conformsToProtocol: @protocol (RCTModule )];
644655}
645656
646657/* *
@@ -1104,3 +1115,4 @@ - (void)_invalidateModules
11041115}
11051116
11061117@end
1118+
0 commit comments