/// /// HybridOmniComponent.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. /// https://github.com/mrousavy/nitro /// Copyright © Marc Rousavy @ Margelo /// #include "HybridOmniComponent.hpp" #include #include #include #include #include #include #include #include #include #include namespace margelo::nitro::omni::views { extern const char HybridOmniComponentName[] = "Omni"; HybridOmniProps::HybridOmniProps(const react::PropsParserContext& context, const HybridOmniProps& sourceProps, const react::RawProps& rawProps): react::ViewProps(context, sourceProps, rawProps, filterObjectKeys), isRed([&]() -> CachedProp { try { const react::RawValue* rawValue = rawProps.at("isRed", nullptr, nullptr); if (rawValue == nullptr) return sourceProps.isRed; const auto& [runtime, value] = (std::pair)*rawValue; return CachedProp::fromRawValue(*runtime, value, sourceProps.isRed); } catch (const std::exception& exc) { throw std::runtime_error(std::string("Omni.isRed: ") + exc.what()); } }()), hybridRef([&]() -> CachedProp& /* ref */)>>> { try { const react::RawValue* rawValue = rawProps.at("hybridRef", nullptr, nullptr); if (rawValue == nullptr) return sourceProps.hybridRef; const auto& [runtime, value] = (std::pair)*rawValue; return CachedProp& /* ref */)>>>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, PropNameIDCache::get(*runtime, "f")), sourceProps.hybridRef); } catch (const std::exception& exc) { throw std::runtime_error(std::string("Omni.hybridRef: ") + exc.what()); } }()) { } bool HybridOmniProps::filterObjectKeys(const std::string& propName) { switch (hashString(propName)) { case hashString("isRed"): return true; case hashString("hybridRef"): return true; default: return false; } } HybridOmniComponentDescriptor::HybridOmniComponentDescriptor(const react::ComponentDescriptorParameters& parameters) : ConcreteComponentDescriptor(parameters, react::RawPropsParser(/* enableJsiParser */ true)) {} std::shared_ptr HybridOmniComponentDescriptor::cloneProps(const react::PropsParserContext& context, const std::shared_ptr& props, react::RawProps rawProps) const { // 1. Prepare raw props parser rawProps.parse(rawPropsParser_); // 2. Copy props with Nitro's cached copy constructor return HybridOmniShadowNode::Props(context, /* & */ rawProps, props); } #ifdef ANDROID void HybridOmniComponentDescriptor::adopt(react::ShadowNode& shadowNode) const { // This is called immediately after `ShadowNode` is created, cloned or in progress. // On Android, we need to wrap props in our state, which gets routed through Java and later unwrapped in JNI/C++. auto& concreteShadowNode = static_cast(shadowNode); const std::shared_ptr& constProps = concreteShadowNode.getConcreteSharedProps(); const std::shared_ptr& props = std::const_pointer_cast(constProps); HybridOmniState state{props}; concreteShadowNode.setStateData(std::move(state)); } #endif } // namespace margelo::nitro::omni::views