From 0217d7e19cf10b6b2261ccd8e78f6bf02a55fed4 Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Tue, 3 Dec 2024 22:23:04 -0800 Subject: [PATCH] have RCTInstance decorate non-app provided turbomodules with bridgeless APIs (#48053) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48053 Changelog: [Internal] `getModuleInstanceFromClass:` is a delegate method intended to be implemented by the product layer to provide modules. if it is not implemented to return a module for a given key, `RCTTurboModuleManager` will simply call `new` on the TM class. however, these two paths differentiate - for `getModuleInstanceFromClass:`, we will call `_attachBridgelessAPIsToModule:` which provides objects like surfacePresenter to the native module. if we fallback to calling `new`, then this attachment does not happen, even if the app has already been migrated to bridgeless modules. thus, the fix in the case is to lift the fallback into RCTInstance as well, and decorate the APIs onto the new fallback. Reviewed By: cipolleschi Differential Revision: D66675034 fbshipit-source-id: 1ab89a4006d05f744f5d42b5de786ccea4d4a55d --- .../platform/ios/ReactCommon/RCTInstance.mm | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm index 561fac8dd57..588f6a3f02b 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm @@ -185,22 +185,19 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags) - (Class)getModuleClassFromName:(const char *)name { - if ([_appTMMDelegate respondsToSelector:@selector(getModuleClassFromName:)]) { - return [_appTMMDelegate getModuleClassFromName:name]; - } - - return nil; + return [_appTMMDelegate getModuleClassFromName:name]; } - (id)getModuleInstanceFromClass:(Class)moduleClass { - if ([_appTMMDelegate respondsToSelector:@selector(getModuleInstanceFromClass:)]) { - id module = [_appTMMDelegate getModuleInstanceFromClass:moduleClass]; - [self _attachBridgelessAPIsToModule:module]; - return module; + id module = [_appTMMDelegate getModuleInstanceFromClass:moduleClass]; + + if (!module) { + module = [moduleClass new]; } - return nil; + [self _attachBridgelessAPIsToModule:module]; + return module; } - (std::shared_ptr)getTurboModule:(const std::string &)name