mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:
committed by
Facebook GitHub Bot
parent
a564908630
commit
ef546ba5f5
+4
@@ -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.
|
||||
*/
|
||||
|
||||
+10
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user