Files
nitro/packages/react-native-nitro-modules/cpp/entrypoint/HybridNitroModulesProxy.cpp
T
Marc RousavyandGitHub 04e73d8c1d feat: Add native NITRO_VERSION to C++ codebase and warn if it's out of sync (#398)
* feat: Add `NITRO_VERSION` to NitroDefines.hpp and update it post bump

* feat: Log warning if nitro versions don't match
2024-12-05 15:01:37 +01:00

70 lines
2.2 KiB
C++

//
// HybridNitroModulesProxy.hpp
// NitroModules
//
// Created by Marc Rousavy on 05.10.24
//
#include "HybridNitroModulesProxy.hpp"
#include "HybridObjectRegistry.hpp"
#include "NitroDefines.hpp"
namespace margelo::nitro {
void HybridNitroModulesProxy::loadHybridMethods() {
HybridObject::loadHybridMethods();
registerHybrids(this, [](Prototype& prototype) {
prototype.registerHybridMethod("createHybridObject", &HybridNitroModulesProxy::createHybridObject);
prototype.registerHybridMethod("hasHybridObject", &HybridNitroModulesProxy::hasHybridObject);
prototype.registerHybridMethod("getAllHybridObjectNames", &HybridNitroModulesProxy::getAllHybridObjectNames);
prototype.registerHybridMethod("box", &HybridNitroModulesProxy::box);
prototype.registerRawHybridMethod("hasNativeState", 1, &HybridNitroModulesProxy::hasNativeState);
prototype.registerHybridGetter("buildType", &HybridNitroModulesProxy::getBuildType);
prototype.registerHybridGetter("version", &HybridNitroModulesProxy::getVersion);
});
}
// Hybrid Object Registry
std::shared_ptr<HybridObject> HybridNitroModulesProxy::createHybridObject(const std::string& name) {
return HybridObjectRegistry::createHybridObject(name);
}
bool HybridNitroModulesProxy::hasHybridObject(const std::string& name) {
return HybridObjectRegistry::hasHybridObject(name);
}
std::vector<std::string> HybridNitroModulesProxy::getAllHybridObjectNames() {
return HybridObjectRegistry::getAllHybridObjectNames();
}
// Helpers
std::shared_ptr<BoxedHybridObject> HybridNitroModulesProxy::box(const std::shared_ptr<HybridObject>& hybridObject) {
return std::make_shared<BoxedHybridObject>(hybridObject);
}
jsi::Value HybridNitroModulesProxy::hasNativeState(jsi::Runtime& runtime, const jsi::Value&, const jsi::Value* args, size_t size) {
if (size != 1 || !args[0].isObject()) {
return false;
}
return args[0].getObject(runtime).hasNativeState(runtime);
}
// Build Info
std::string HybridNitroModulesProxy::getBuildType() {
#ifdef NITRO_DEBUG
return "debug";
#else
return "release";
#endif
}
std::string HybridNitroModulesProxy::getVersion() {
return NITRO_VERSION;
}
} // namespace margelo::nitro