From 80ecbdf2b28f3ee6c80a183a09c32482caa36134 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Thu, 4 May 2023 11:26:51 -0700 Subject: [PATCH] ObjCTurboModule: Migrate over to id Summary: ## Definitions - **id**: A native module object. - **id**: A turbo module object. ## Changes This diff refactors the ObjCTurboModule, so that it can create perform method dispatch for legacy native module objects. This change shouldn't impact any existing behaviour of the TurboModule system, because all turbo modules are also native modules. ## Rationale In Bridgeless mode, the TurboModule system will now have to manage legacy native modules. Changelog: [Internal] Reviewed By: philIip Differential Revision: D44646371 fbshipit-source-id: 946dcb82bdfced60f5c29fda8e3b4a92cda8acb0 --- .../core/platform/ios/ReactCommon/RCTTurboModule.h | 4 ++-- .../core/platform/ios/ReactCommon/RCTTurboModule.mm | 6 +++--- .../core/platform/ios/ReactCommon/RCTTurboModuleManager.mm | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.h b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.h index 1021b3adce6..4dc6b8f2330 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.h +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.h @@ -40,7 +40,7 @@ class JSI_EXPORT ObjCTurboModule : public TurboModule { // TODO(T65603471): Should we unify this with a Fabric abstraction? struct InitParams { std::string moduleName; - id instance; + id instance; std::shared_ptr jsInvoker; std::shared_ptr nativeInvoker; bool isSyncModule; @@ -56,7 +56,7 @@ class JSI_EXPORT ObjCTurboModule : public TurboModule { const jsi::Value *args, size_t count); - id instance_; + id instance_; std::shared_ptr nativeInvoker_; protected: diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm index dc5b5731658..93271d2f818 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm @@ -385,13 +385,13 @@ id ObjCTurboModule::performMethodInvocation( NSMutableArray *retainedObjectsForInvocation) { __block id result; - __weak id weakModule = instance_; + __weak id weakModule = instance_; const char *moduleName = name_.c_str(); std::string methodNameStr{methodName}; __block int32_t asyncCallCounter = 0; void (^block)() = ^{ - id strongModule = weakModule; + id strongModule = weakModule; if (!strongModule) { return; } @@ -650,7 +650,7 @@ NSInvocation *ObjCTurboModule::createMethodInvocation( NSMutableArray *retainedObjectsForInvocation) { const char *moduleName = name_.c_str(); - const id module = instance_; + const id module = instance_; if (isSync) { TurboModulePerfLogger::syncMethodCallArgConversionStart(moduleName, methodName); diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm index 8cbbfb14a05..cf440aef874 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm @@ -307,7 +307,7 @@ static Class getFallbackClassFromName(const char *name) if ([module respondsToSelector:@selector(getTurboModule:)]) { ObjCTurboModule::InitParams params = { .moduleName = moduleName, - .instance = (id)module, + .instance = module, .jsInvoker = _jsInvoker, .nativeInvoker = nativeInvoker, .isSyncModule = methodQueue == RCTJSThread,