Expose convertObjCObjectToJSIValue from RCTTurboModule.h (#37155)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37155

Rationale: The interop TurboModule class will need to use this method to convert return ObjC values to JavaScript values.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D44807335

fbshipit-source-id: d44cd1d5effccd8258e034008bd230b299d20451
This commit is contained in:
Ramanpreet Nara
2023-04-30 03:28:33 -07:00
committed by Facebook GitHub Bot
parent a564908630
commit ef546ba5f5
2 changed files with 14 additions and 4 deletions
@@ -28,6 +28,10 @@ namespace facebook::react {
class CallbackWrapper;
class Instance;
namespace TurboModuleConvertUtils {
jsi::Value convertObjCObjectToJSIValue(jsi::Runtime &runtime, id value);
}
/**
* ObjC++ specific TurboModule base class.
*/
@@ -29,6 +29,7 @@
using namespace facebook;
using namespace facebook::react;
using namespace facebook::react::TurboModuleConvertUtils;
static int32_t getUniqueId()
{
@@ -36,6 +37,10 @@ static int32_t getUniqueId()
return counter++;
}
namespace facebook {
namespace react {
namespace TurboModuleConvertUtils {
/**
* All static helper functions are ObjC++ specific.
*/
@@ -54,7 +59,7 @@ static jsi::String convertNSStringToJSIString(jsi::Runtime &runtime, NSString *v
return jsi::String::createFromUtf8(runtime, [value UTF8String] ?: "");
}
static jsi::Value convertObjCObjectToJSIValue(jsi::Runtime &runtime, id value);
jsi::Value convertObjCObjectToJSIValue(jsi::Runtime &runtime, id value);
static jsi::Object convertNSDictionaryToJSIObject(jsi::Runtime &runtime, NSDictionary *value)
{
jsi::Object result = jsi::Object(runtime);
@@ -82,7 +87,7 @@ static std::vector<jsi::Value> convertNSArrayToStdVector(jsi::Runtime &runtime,
return result;
}
static jsi::Value convertObjCObjectToJSIValue(jsi::Runtime &runtime, id value)
jsi::Value convertObjCObjectToJSIValue(jsi::Runtime &runtime, id value)
{
if ([value isKindOfClass:[NSString class]]) {
return convertNSStringToJSIString(runtime, (NSString *)value);
@@ -211,8 +216,6 @@ convertJSIFunctionToCallback(jsi::Runtime &runtime, const jsi::Function &value,
return [callback copy];
}
namespace facebook::react {
static jsi::Value createJSRuntimeError(jsi::Runtime &runtime, const std::string &message)
{
return runtime.global().getPropertyAsFunction(runtime, "Error").call(runtime, message);
@@ -237,6 +240,8 @@ static jsi::JSError convertNSExceptionToJSError(jsi::Runtime &runtime, NSExcepti
return {runtime, std::move(error)};
}
}
jsi::Value ObjCTurboModule::createPromise(jsi::Runtime &runtime, std::string methodName, PromiseInvocationBlock invoke)
{
if (!invoke) {
@@ -771,4 +776,5 @@ void ObjCTurboModule::setMethodArgConversionSelector(NSString *methodName, int a
methodArgConversionSelectors_[methodName][argIndex] = selectorValue;
}
}
} // namespace facebook::react