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 bdfbeeb596af52..c3dc8a82fce940 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 @@ -45,6 +45,7 @@ class JSI_EXPORT ObjCTurboModule : public TurboModule { std::shared_ptr jsInvoker; std::shared_ptr nativeMethodCallInvoker; bool isSyncModule; + bool shouldVoidMethodsExecuteSync; }; ObjCTurboModule(const InitParams ¶ms); @@ -112,6 +113,9 @@ class JSI_EXPORT ObjCTurboModule : public TurboModule { // Does the NativeModule dispatch async methods to the JS thread? const bool isSyncModule_; + // Should void methods execute synchronously? + const bool shouldVoidMethodsExecuteSync_; + /** * TODO(ramanpreet): * Investigate an optimization that'll let us get rid of this NSMutableDictionary. 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 7c4cb68787ac81..b9a0996bff3a0e 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 @@ -680,6 +680,10 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s bool ObjCTurboModule::isMethodSync(TurboModuleMethodValueKind returnType) { + if (returnType == VoidKind && shouldVoidMethodsExecuteSync_) { + return true; + } + return isSyncModule_ || !(returnType == VoidKind || returnType == PromiseKind); } @@ -687,7 +691,8 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s : TurboModule(params.moduleName, params.jsInvoker), instance_(params.instance), nativeMethodCallInvoker_(params.nativeMethodCallInvoker), - isSyncModule_(params.isSyncModule) + isSyncModule_(params.isSyncModule), + shouldVoidMethodsExecuteSync_(params.shouldVoidMethodsExecuteSync) { } 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 2de7da87ff8088..060cc5743c3325 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 @@ -375,6 +375,7 @@ - (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy .jsInvoker = _jsInvoker, .nativeMethodCallInvoker = nativeMethodCallInvoker, .isSyncModule = methodQueue == RCTJSThread, + .shouldVoidMethodsExecuteSync = false, }; auto turboModule = [(id)module getTurboModule:params]; @@ -437,6 +438,7 @@ - (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy .jsInvoker = _jsInvoker, .nativeMethodCallInvoker = std::move(nativeMethodCallInvoker), .isSyncModule = methodQueue == RCTJSThread, + .shouldVoidMethodsExecuteSync = false, }; auto turboModule = std::make_shared(params);