Files
nitro/packages/react-native-nitro-modules/cpp/core/BoxedHybridObject.cpp
T
Marc RousavyandGitHub 1128d6a3c6 feat: Add NitroModules.box(...) to support using Nitro Modules from any Runtime/Worklets context (#138)
* feat: Add `NitroModules.box(...)` to support using Nitro Modules from any Runtime/Worklets context

* feat: Add `getPropertyNames` for `BoxedHybridObject`

* docs: Create Worklets/Threading docs
2024-09-17 14:45:28 +02:00

30 lines
885 B
C++

//
// BoxedHybridObject.cpp
// NitroModules
//
// Created by Marc Rousavy on 17.09.24.
//
#include "BoxedHybridObject.hpp"
namespace margelo::nitro {
std::vector<jsi::PropNameID> BoxedHybridObject::getPropertyNames(facebook::jsi::Runtime& runtime) {
return jsi::PropNameID::names(runtime, "unbox");
}
jsi::Value BoxedHybridObject::get(jsi::Runtime& runtime, const jsi::PropNameID& propName) {
std::string name = propName.utf8(runtime);
if (name == "unbox") {
return jsi::Function::createFromHostFunction(
runtime, jsi::PropNameID::forUtf8(runtime, "unbox"), 0,
[hybridObject = _hybridObject](jsi::Runtime& runtime, const jsi::Value& thisArg, const jsi::Value* args,
size_t count) -> jsi::Value { return hybridObject->toObject(runtime); });
}
return jsi::Value::undefined();
}
} // namespace margelo::nitro