diff --git a/React/Base/RCTBridgeModule.h b/React/Base/RCTBridgeModule.h index a01e4117a..b51eb71e6 100644 --- a/React/Base/RCTBridgeModule.h +++ b/React/Base/RCTBridgeModule.h @@ -326,7 +326,6 @@ RCT_EXTERN void RCTRegisterModule(Class); \ * Experimental. * A protocol to declare that a class supports TurboModule. * This may be removed in the future. + * See RCTTurboModule.h for actual signature. */ -@protocol RCTTurboModule - -@end +@protocol RCTTurboModule; diff --git a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModule.h b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModule.h index 3559540f0..084a23e53 100644 --- a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModule.h +++ b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModule.h @@ -38,19 +38,18 @@ public: } // namespace react } // namespace facebook +@protocol RCTTurboModule + +@optional + +// This should be required, after migration is done. +- (std::shared_ptr)getTurboModuleWithJsInvoker:(std::shared_ptr)jsInvoker; + +@end + // TODO: Consolidate this extension with the one in RCTSurfacePresenter. @interface RCTBridge () - (std::shared_ptr)jsMessageThread; @end - -/** - * A backward-compatible protocol to be adopted by an existing RCTCxxModule-based class - * so that it can support the TurboModule system. - */ -@protocol RCTTurboCxxModule - -- (std::shared_ptr)getTurboModuleWithJsInvoker:(std::shared_ptr)jsInvoker; - -@end diff --git a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm index 46f69fb62..eb1e4c3c8 100644 --- a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm +++ b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm @@ -111,17 +111,18 @@ static Class getFallbackClassFromName(const char *name) { } } + if ([module respondsToSelector:@selector(getTurboModuleWithJsInvoker:)]) { + return [module getTurboModuleWithJsInvoker:strongSelf->_jsInvoker]; + } + // RCTCxxModule compatibility layer. if ([moduleClass isSubclassOfClass:RCTCxxModule.class]) { - if ([module respondsToSelector:@selector(getTurboModuleWithJsInvoker:)]) { - return [((id)module) getTurboModuleWithJsInvoker:strongSelf->_jsInvoker]; - } - // Use TurboCxxModule compat class to wrap the CxxModule instance. // This is only for migration convenience, despite less performant. return std::make_shared([((RCTCxxModule *)module) createModule], strongSelf->_jsInvoker); } + // This may be needed for migration purpose in case the module class doesn't provide the static getter. return [strongSelf->_delegate getTurboModule:name instance:module jsInvoker:strongSelf->_jsInvoker]; };