diff --git a/packages/react-native/ReactCommon/react/bridging/Class.h b/packages/react-native/ReactCommon/react/bridging/Class.h index d0cc976f543..24217db66c9 100644 --- a/packages/react-native/ReactCommon/react/bridging/Class.h +++ b/packages/react-native/ReactCommon/react/bridging/Class.h @@ -50,7 +50,7 @@ T callFromJs( rt, fromJs(rt, std::forward(args), jsInvoker)...), jsInvoker); - } else if constexpr (is_optional_v) { + } else if constexpr (is_optional_jsi_v) { static_assert( is_optional_v ? supportsToJs @@ -70,10 +70,8 @@ T callFromJs( } return convert(rt, std::move(result)); - } else { static_assert(std::is_convertible_v, "Incompatible return type"); - return (instance->*method)( rt, fromJs(rt, std::forward(args), jsInvoker)...); } diff --git a/packages/react-native/ReactCommon/react/bridging/Convert.h b/packages/react-native/ReactCommon/react/bridging/Convert.h index d2e0f8ed223..43d35ed5059 100644 --- a/packages/react-native/ReactCommon/react/bridging/Convert.h +++ b/packages/react-native/ReactCommon/react/bridging/Convert.h @@ -33,6 +33,14 @@ struct is_optional> : std::true_type {}; template inline constexpr bool is_optional_v = is_optional::value; +template +inline constexpr bool is_optional_jsi_v = false; + +template +inline constexpr bool + is_optional_jsi_v>> = + is_jsi_v; + template struct Converter; diff --git a/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.cpp b/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.cpp index 7c3d62da2ba..b0c1aa056bc 100644 --- a/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.cpp +++ b/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.cpp @@ -117,10 +117,10 @@ AsyncPromise NativeCxxModuleExample::getValueWithPromise( return promise; } -bool NativeCxxModuleExample::getWithWithOptionalArgs( +std::optional NativeCxxModuleExample::getWithWithOptionalArgs( jsi::Runtime &rt, std::optional optionalArg) { - return optionalArg.value_or(false); + return optionalArg; } void NativeCxxModuleExample::voidFunc(jsi::Runtime &rt) { diff --git a/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.h b/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.h index 2a1538bb645..1ce49f367a9 100644 --- a/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.h +++ b/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.h @@ -120,7 +120,7 @@ class NativeCxxModuleExample AsyncPromise getValueWithPromise(jsi::Runtime &rt, bool error); - bool getWithWithOptionalArgs( + std::optional getWithWithOptionalArgs( jsi::Runtime &rt, std::optional optionalArg); diff --git a/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.js b/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.js index f8d9e1b0df2..7e2c10f97ee 100644 --- a/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.js +++ b/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.js @@ -70,7 +70,7 @@ export interface Spec extends TurboModule { +getValue: (x: number, y: string, z: ObjectStruct) => ValueStruct; +getValueWithCallback: (callback: (value: string) => void) => void; +getValueWithPromise: (error: boolean) => Promise; - +getWithWithOptionalArgs: (optionalArg?: boolean) => boolean; + +getWithWithOptionalArgs: (optionalArg?: boolean) => ?boolean; +voidFunc: () => void; +emitCustomDeviceEvent: (eventName: string) => void; }