Files
nitro/packages/react-native-nitro-modules/cpp/views/ViewPropsHolderState.hpp
T
Marc RousavyandGitHub 670f4654f5 feat: Move react::ComponentDescriptor into Nitro Modules core via C++ template (#1486)
* feat: Add base files

* use type

* clean header

* Update ViewComponentDescriptor.hpp

* Use it!

* fix build error

* comments

* Update JSIRawPropsParser.hpp

* remove raw prop parser ig

* fix: remove deleted header from podspec
2026-08-20 10:50:14 +02:00

49 lines
1.2 KiB
C++

//
// Created by Marc Rousavy on 19.08.26.
//
#pragma once
#include <react/renderer/core/ConcreteComponentDescriptor.h>
namespace margelo::nitro {
using namespace facebook;
/**
* A class that conforms to `react::StateData`, which
* only holds the given `TProps` via a `shared_ptr`.
*
* This is useful to set props via a custom route through
* JNI on Android, instead of going through react-native's
* JNI/folly prop parser which is type-limited.
*/
template <typename TProps>
struct ViewPropsHolderState final {
public:
ViewPropsHolderState() = default;
explicit ViewPropsHolderState(const std::shared_ptr<TProps>& props) : _props(props) {}
public:
[[nodiscard]]
const std::shared_ptr<TProps>& getProps() const {
return _props;
}
public:
#ifdef ANDROID
ViewPropsHolderState(const ViewPropsHolderState& /* previousState */, folly::dynamic /* data */) {}
folly::dynamic getDynamic() const {
throw std::runtime_error("ViewPropsHolderState<T> does not support folly!");
}
react::MapBuffer getMapBuffer() const {
throw std::runtime_error("ViewPropsHolderState<T> does not support MapBuffer!");
};
#endif
private:
std::shared_ptr<TProps> _props;
};
} // namespace margelo::nitro