Implement view

This commit is contained in:
2026-04-10 20:12:34 +02:00
parent fd40915bc9
commit 626380bcc4
14 changed files with 126 additions and 30 deletions
+2
View File
@@ -14,6 +14,8 @@ namespace margelo::nitro::omni {
HybridObject::loadHybridMethods();
// load custom methods/properties
registerHybrids(this, [](Prototype& prototype) {
prototype.registerHybridGetter("player", &HybridOmniViewSpec::getPlayer);
prototype.registerHybridSetter("player", &HybridOmniViewSpec::setPlayer);
prototype.registerHybridGetter("autoplay", &HybridOmniViewSpec::getAutoplay);
prototype.registerHybridSetter("autoplay", &HybridOmniViewSpec::setAutoplay);
prototype.registerHybridGetter("showNotification", &HybridOmniViewSpec::getShowNotification);
+6 -1
View File
@@ -13,8 +13,11 @@
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
// Forward declaration of `HybridOmniPlayerSpec` to properly resolve imports.
namespace margelo::nitro::omni { class HybridOmniPlayerSpec; }
#include <memory>
#include "HybridOmniPlayerSpec.hpp"
#include <optional>
namespace margelo::nitro::omni {
@@ -44,6 +47,8 @@ namespace margelo::nitro::omni {
public:
// Properties
virtual std::shared_ptr<HybridOmniPlayerSpec> getPlayer() = 0;
virtual void setPlayer(const std::shared_ptr<HybridOmniPlayerSpec>& player) = 0;
virtual std::optional<bool> getAutoplay() = 0;
virtual void setAutoplay(std::optional<bool> autoplay) = 0;
virtual std::optional<bool> getShowNotification() = 0;
@@ -26,6 +26,16 @@ namespace margelo::nitro::omni::views {
const HybridOmniViewProps& sourceProps,
const react::RawProps& rawProps):
react::ViewProps(context, sourceProps, rawProps, filterObjectKeys),
player([&]() -> CachedProp<std::shared_ptr<HybridOmniPlayerSpec>> {
try {
const react::RawValue* rawValue = rawProps.at("player", nullptr, nullptr);
if (rawValue == nullptr) return sourceProps.player;
const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
return CachedProp<std::shared_ptr<HybridOmniPlayerSpec>>::fromRawValue(*runtime, value, sourceProps.player);
} catch (const std::exception& exc) {
throw std::runtime_error(std::string("OmniView.player: ") + exc.what());
}
}()),
autoplay([&]() -> CachedProp<std::optional<bool>> {
try {
const react::RawValue* rawValue = rawProps.at("autoplay", nullptr, nullptr);
@@ -69,6 +79,7 @@ namespace margelo::nitro::omni::views {
bool HybridOmniViewProps::filterObjectKeys(const std::string& propName) {
switch (hashString(propName)) {
case hashString("player"): return true;
case hashString("autoplay"): return true;
case hashString("showNotification"): return true;
case hashString("autoPip"): return true;
@@ -16,8 +16,9 @@
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <react/renderer/components/view/ViewProps.h>
#include <optional>
#include <memory>
#include "HybridOmniPlayerSpec.hpp"
#include <optional>
#include "HybridOmniViewSpec.hpp"
#include <functional>
@@ -41,6 +42,7 @@ namespace margelo::nitro::omni::views {
const react::RawProps& rawProps);
public:
CachedProp<std::shared_ptr<HybridOmniPlayerSpec>> player;
CachedProp<std::optional<bool>> autoplay;
CachedProp<std::optional<bool>> showNotification;
CachedProp<std::optional<bool>> autoPip;
+1
View File
@@ -4,6 +4,7 @@
"bubblingEventTypes": {},
"directEventTypes": {},
"validAttributes": {
"player": true,
"autoplay": true,
"showNotification": true,
"autoPip": true,