fix(nitro): fix native codegen

This commit is contained in:
2026-07-19 19:59:56 +02:00
parent 5921c2da59
commit 66471967e3
48 changed files with 1179 additions and 82 deletions
+88
View File
@@ -0,0 +1,88 @@
///
/// CastStatus.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///
#pragma once
#if __has_include(<NitroModules/NitroHash.hpp>)
#include <NitroModules/NitroHash.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/JSIConverter.hpp>)
#include <NitroModules/JSIConverter.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/NitroDefines.hpp>)
#include <NitroModules/NitroDefines.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
namespace margelo::nitro::omni {
/**
* An enum which can be represented as a JavaScript union (CastStatus).
*/
enum class CastStatus {
CONNECTING SWIFT_NAME(connecting) = 0,
CONNECTED SWIFT_NAME(connected) = 1,
AVAILABLE SWIFT_NAME(available) = 2,
UNAVAILABLE SWIFT_NAME(unavailable) = 3,
UNSUPPORTED SWIFT_NAME(unsupported) = 4,
} CLOSED_ENUM;
} // namespace margelo::nitro::omni
namespace margelo::nitro {
// C++ CastStatus <> JS CastStatus (union)
template <>
struct JSIConverter<margelo::nitro::omni::CastStatus> final {
static inline margelo::nitro::omni::CastStatus fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
switch (hashString(unionValue.c_str(), unionValue.size())) {
case hashString("connecting"): return margelo::nitro::omni::CastStatus::CONNECTING;
case hashString("connected"): return margelo::nitro::omni::CastStatus::CONNECTED;
case hashString("available"): return margelo::nitro::omni::CastStatus::AVAILABLE;
case hashString("unavailable"): return margelo::nitro::omni::CastStatus::UNAVAILABLE;
case hashString("unsupported"): return margelo::nitro::omni::CastStatus::UNSUPPORTED;
default: [[unlikely]]
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum CastStatus - invalid value!");
}
}
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::omni::CastStatus arg) {
switch (arg) {
case margelo::nitro::omni::CastStatus::CONNECTING: return JSIConverter<std::string>::toJSI(runtime, "connecting");
case margelo::nitro::omni::CastStatus::CONNECTED: return JSIConverter<std::string>::toJSI(runtime, "connected");
case margelo::nitro::omni::CastStatus::AVAILABLE: return JSIConverter<std::string>::toJSI(runtime, "available");
case margelo::nitro::omni::CastStatus::UNAVAILABLE: return JSIConverter<std::string>::toJSI(runtime, "unavailable");
case margelo::nitro::omni::CastStatus::UNSUPPORTED: return JSIConverter<std::string>::toJSI(runtime, "unsupported");
default: [[unlikely]]
throw std::invalid_argument("Cannot convert CastStatus to JS - invalid value: "
+ std::to_string(static_cast<int>(arg)) + "!");
}
}
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
if (!value.isString()) {
return false;
}
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
switch (hashString(unionValue.c_str(), unionValue.size())) {
case hashString("connecting"):
case hashString("connected"):
case hashString("available"):
case hashString("unavailable"):
case hashString("unsupported"):
return true;
default:
return false;
}
}
};
} // namespace margelo::nitro
+2
View File
@@ -36,10 +36,12 @@ namespace margelo::nitro::omni {
prototype.registerHybridGetter("muted", &HybridOmniPlayerSpec::getMuted);
prototype.registerHybridSetter("muted", &HybridOmniPlayerSpec::setMuted);
prototype.registerHybridGetter("isAutoQuality", &HybridOmniPlayerSpec::getIsAutoQuality);
prototype.registerHybridGetter("castStatus", &HybridOmniPlayerSpec::getCastStatus);
prototype.registerHybridMethod("setSource", &HybridOmniPlayerSpec::setSource);
prototype.registerHybridMethod("play", &HybridOmniPlayerSpec::play);
prototype.registerHybridMethod("pause", &HybridOmniPlayerSpec::pause);
prototype.registerHybridMethod("seekBy", &HybridOmniPlayerSpec::seekBy);
prototype.registerHybridMethod("toggleCastStatus", &HybridOmniPlayerSpec::toggleCastStatus);
prototype.registerHybridMethod("playPrev", &HybridOmniPlayerSpec::playPrev);
prototype.registerHybridMethod("playNext", &HybridOmniPlayerSpec::playNext);
prototype.registerHybridMethod("selectVideo", &HybridOmniPlayerSpec::selectVideo);
+5
View File
@@ -21,6 +21,8 @@ namespace margelo::nitro::omni { struct Track; }
namespace margelo::nitro::omni { struct Rendition; }
// Forward declaration of `PlayerStatus` to properly resolve imports.
namespace margelo::nitro::omni { enum class PlayerStatus; }
// Forward declaration of `CastStatus` to properly resolve imports.
namespace margelo::nitro::omni { enum class CastStatus; }
// Forward declaration of `Source` to properly resolve imports.
namespace margelo::nitro::omni { struct Source; }
@@ -31,6 +33,7 @@ namespace margelo::nitro::omni { struct Source; }
#include <vector>
#include "Rendition.hpp"
#include "PlayerStatus.hpp"
#include "CastStatus.hpp"
#include "Source.hpp"
namespace margelo::nitro::omni {
@@ -82,6 +85,7 @@ namespace margelo::nitro::omni {
virtual bool getMuted() = 0;
virtual void setMuted(bool muted) = 0;
virtual bool getIsAutoQuality() = 0;
virtual CastStatus getCastStatus() = 0;
public:
// Methods
@@ -89,6 +93,7 @@ namespace margelo::nitro::omni {
virtual void play() = 0;
virtual void pause() = 0;
virtual void seekBy(double offset) = 0;
virtual void toggleCastStatus() = 0;
virtual void playPrev() = 0;
virtual void playNext() = 0;
virtual void selectVideo(const Track& video) = 0;
+2
View File
@@ -20,6 +20,8 @@ namespace margelo::nitro::omni {
prototype.registerHybridSetter("autoplay", &HybridOmniViewSpec::setAutoplay);
prototype.registerHybridGetter("autoPip", &HybridOmniViewSpec::getAutoPip);
prototype.registerHybridSetter("autoPip", &HybridOmniViewSpec::setAutoPip);
prototype.registerHybridGetter("subtitleAssets", &HybridOmniViewSpec::getSubtitleAssets);
prototype.registerHybridSetter("subtitleAssets", &HybridOmniViewSpec::setSubtitleAssets);
});
}
+5
View File
@@ -15,10 +15,13 @@
// Forward declaration of `HybridOmniPlayerSpec` to properly resolve imports.
namespace margelo::nitro::omni { class HybridOmniPlayerSpec; }
// Forward declaration of `SubtitleAssets` to properly resolve imports.
namespace margelo::nitro::omni { struct SubtitleAssets; }
#include <memory>
#include "HybridOmniPlayerSpec.hpp"
#include <optional>
#include "SubtitleAssets.hpp"
namespace margelo::nitro::omni {
@@ -53,6 +56,8 @@ namespace margelo::nitro::omni {
virtual void setAutoplay(std::optional<bool> autoplay) = 0;
virtual std::optional<bool> getAutoPip() = 0;
virtual void setAutoPip(std::optional<bool> autoPip) = 0;
virtual std::optional<SubtitleAssets> getSubtitleAssets() = 0;
virtual void setSubtitleAssets(const std::optional<SubtitleAssets>& subtitleAssets) = 0;
public:
// Methods
+96
View File
@@ -0,0 +1,96 @@
///
/// JassubAssets.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///
#pragma once
#if __has_include(<NitroModules/JSIConverter.hpp>)
#include <NitroModules/JSIConverter.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/NitroDefines.hpp>)
#include <NitroModules/NitroDefines.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/JSIHelpers.hpp>)
#include <NitroModules/JSIHelpers.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
#include <NitroModules/PropNameIDCache.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#include <string>
#include <optional>
namespace margelo::nitro::omni {
/**
* A struct which can be represented as a JavaScript object (JassubAssets).
*/
struct JassubAssets final {
public:
std::optional<std::string> workerUrl SWIFT_PRIVATE;
std::optional<std::string> wasmUrl SWIFT_PRIVATE;
std::optional<std::string> modernWasmUrl SWIFT_PRIVATE;
std::optional<std::string> fontUrl SWIFT_PRIVATE;
public:
JassubAssets() = default;
explicit JassubAssets(std::optional<std::string> workerUrl, std::optional<std::string> wasmUrl, std::optional<std::string> modernWasmUrl, std::optional<std::string> fontUrl): workerUrl(workerUrl), wasmUrl(wasmUrl), modernWasmUrl(modernWasmUrl), fontUrl(fontUrl) {}
public:
friend bool operator==(const JassubAssets& lhs, const JassubAssets& rhs) = default;
};
} // namespace margelo::nitro::omni
namespace margelo::nitro {
// C++ JassubAssets <> JS JassubAssets (object)
template <>
struct JSIConverter<margelo::nitro::omni::JassubAssets> final {
static inline margelo::nitro::omni::JassubAssets fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
jsi::Object obj = arg.asObject(runtime);
return margelo::nitro::omni::JassubAssets(
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "workerUrl"))),
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "wasmUrl"))),
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "modernWasmUrl"))),
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fontUrl")))
);
}
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::omni::JassubAssets& arg) {
jsi::Object obj(runtime);
obj.setProperty(runtime, PropNameIDCache::get(runtime, "workerUrl"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.workerUrl));
obj.setProperty(runtime, PropNameIDCache::get(runtime, "wasmUrl"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.wasmUrl));
obj.setProperty(runtime, PropNameIDCache::get(runtime, "modernWasmUrl"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.modernWasmUrl));
obj.setProperty(runtime, PropNameIDCache::get(runtime, "fontUrl"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.fontUrl));
return obj;
}
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
if (!value.isObject()) {
return false;
}
jsi::Object obj = value.getObject(runtime);
if (!nitro::isPlainObject(runtime, obj)) {
return false;
}
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "workerUrl")))) return false;
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "wasmUrl")))) return false;
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "modernWasmUrl")))) return false;
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fontUrl")))) return false;
return true;
}
};
} // namespace margelo::nitro
+4
View File
@@ -35,6 +35,7 @@ namespace margelo::nitro::omni {
PLAYBACKRATE SWIFT_NAME(playbackrate) = 3,
VOLUME SWIFT_NAME(volume) = 4,
ISAUTOQUALITY SWIFT_NAME(isautoquality) = 5,
CASTSTATUS SWIFT_NAME(caststatus) = 6,
} CLOSED_ENUM;
} // namespace margelo::nitro::omni
@@ -53,6 +54,7 @@ namespace margelo::nitro {
case hashString("playbackRate"): return margelo::nitro::omni::NumberProperty::PLAYBACKRATE;
case hashString("volume"): return margelo::nitro::omni::NumberProperty::VOLUME;
case hashString("isAutoQuality"): return margelo::nitro::omni::NumberProperty::ISAUTOQUALITY;
case hashString("castStatus"): return margelo::nitro::omni::NumberProperty::CASTSTATUS;
default: [[unlikely]]
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum NumberProperty - invalid value!");
}
@@ -65,6 +67,7 @@ namespace margelo::nitro {
case margelo::nitro::omni::NumberProperty::PLAYBACKRATE: return JSIConverter<std::string>::toJSI(runtime, "playbackRate");
case margelo::nitro::omni::NumberProperty::VOLUME: return JSIConverter<std::string>::toJSI(runtime, "volume");
case margelo::nitro::omni::NumberProperty::ISAUTOQUALITY: return JSIConverter<std::string>::toJSI(runtime, "isAutoQuality");
case margelo::nitro::omni::NumberProperty::CASTSTATUS: return JSIConverter<std::string>::toJSI(runtime, "castStatus");
default: [[unlikely]]
throw std::invalid_argument("Cannot convert NumberProperty to JS - invalid value: "
+ std::to_string(static_cast<int>(arg)) + "!");
@@ -82,6 +85,7 @@ namespace margelo::nitro {
case hashString("playbackRate"):
case hashString("volume"):
case hashString("isAutoQuality"):
case hashString("castStatus"):
return true;
default:
return false;
+84
View File
@@ -0,0 +1,84 @@
///
/// PgsAssets.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///
#pragma once
#if __has_include(<NitroModules/JSIConverter.hpp>)
#include <NitroModules/JSIConverter.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/NitroDefines.hpp>)
#include <NitroModules/NitroDefines.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/JSIHelpers.hpp>)
#include <NitroModules/JSIHelpers.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
#include <NitroModules/PropNameIDCache.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#include <string>
#include <optional>
namespace margelo::nitro::omni {
/**
* A struct which can be represented as a JavaScript object (PgsAssets).
*/
struct PgsAssets final {
public:
std::optional<std::string> workerUrl SWIFT_PRIVATE;
public:
PgsAssets() = default;
explicit PgsAssets(std::optional<std::string> workerUrl): workerUrl(workerUrl) {}
public:
friend bool operator==(const PgsAssets& lhs, const PgsAssets& rhs) = default;
};
} // namespace margelo::nitro::omni
namespace margelo::nitro {
// C++ PgsAssets <> JS PgsAssets (object)
template <>
struct JSIConverter<margelo::nitro::omni::PgsAssets> final {
static inline margelo::nitro::omni::PgsAssets fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
jsi::Object obj = arg.asObject(runtime);
return margelo::nitro::omni::PgsAssets(
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "workerUrl")))
);
}
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::omni::PgsAssets& arg) {
jsi::Object obj(runtime);
obj.setProperty(runtime, PropNameIDCache::get(runtime, "workerUrl"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.workerUrl));
return obj;
}
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
if (!value.isObject()) {
return false;
}
jsi::Object obj = value.getObject(runtime);
if (!nitro::isPlainObject(runtime, obj)) {
return false;
}
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "workerUrl")))) return false;
return true;
}
};
} // namespace margelo::nitro
+12 -2
View File
@@ -41,8 +41,10 @@ namespace margelo::nitro::omni { enum class MixAudioMode; }
#include <vector>
#include <optional>
#include "Subtitle.hpp"
#include <string>
#include "Metadata.hpp"
#include "MixAudioMode.hpp"
#include <unordered_map>
namespace margelo::nitro::omni {
@@ -54,12 +56,14 @@ namespace margelo::nitro::omni {
std::vector<VideoSrc> src SWIFT_PRIVATE;
std::optional<double> startTime SWIFT_PRIVATE;
std::vector<Subtitle> subtitles SWIFT_PRIVATE;
std::optional<std::vector<std::string>> fonts SWIFT_PRIVATE;
std::optional<Metadata> metadata SWIFT_PRIVATE;
std::optional<MixAudioMode> mixAudio SWIFT_PRIVATE;
std::optional<std::unordered_map<std::string, std::string>> castData SWIFT_PRIVATE;
public:
Source() = default;
explicit Source(std::vector<VideoSrc> src, std::optional<double> startTime, std::vector<Subtitle> subtitles, std::optional<Metadata> metadata, std::optional<MixAudioMode> mixAudio): src(src), startTime(startTime), subtitles(subtitles), metadata(metadata), mixAudio(mixAudio) {}
explicit Source(std::vector<VideoSrc> src, std::optional<double> startTime, std::vector<Subtitle> subtitles, std::optional<std::vector<std::string>> fonts, std::optional<Metadata> metadata, std::optional<MixAudioMode> mixAudio, std::optional<std::unordered_map<std::string, std::string>> castData): src(src), startTime(startTime), subtitles(subtitles), fonts(fonts), metadata(metadata), mixAudio(mixAudio), castData(castData) {}
public:
friend bool operator==(const Source& lhs, const Source& rhs) = default;
@@ -78,8 +82,10 @@ namespace margelo::nitro {
JSIConverter<std::vector<margelo::nitro::omni::VideoSrc>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "src"))),
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startTime"))),
JSIConverter<std::vector<margelo::nitro::omni::Subtitle>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "subtitles"))),
JSIConverter<std::optional<std::vector<std::string>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fonts"))),
JSIConverter<std::optional<margelo::nitro::omni::Metadata>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "metadata"))),
JSIConverter<std::optional<margelo::nitro::omni::MixAudioMode>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mixAudio")))
JSIConverter<std::optional<margelo::nitro::omni::MixAudioMode>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mixAudio"))),
JSIConverter<std::optional<std::unordered_map<std::string, std::string>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "castData")))
);
}
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::omni::Source& arg) {
@@ -87,8 +93,10 @@ namespace margelo::nitro {
obj.setProperty(runtime, PropNameIDCache::get(runtime, "src"), JSIConverter<std::vector<margelo::nitro::omni::VideoSrc>>::toJSI(runtime, arg.src));
obj.setProperty(runtime, PropNameIDCache::get(runtime, "startTime"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.startTime));
obj.setProperty(runtime, PropNameIDCache::get(runtime, "subtitles"), JSIConverter<std::vector<margelo::nitro::omni::Subtitle>>::toJSI(runtime, arg.subtitles));
obj.setProperty(runtime, PropNameIDCache::get(runtime, "fonts"), JSIConverter<std::optional<std::vector<std::string>>>::toJSI(runtime, arg.fonts));
obj.setProperty(runtime, PropNameIDCache::get(runtime, "metadata"), JSIConverter<std::optional<margelo::nitro::omni::Metadata>>::toJSI(runtime, arg.metadata));
obj.setProperty(runtime, PropNameIDCache::get(runtime, "mixAudio"), JSIConverter<std::optional<margelo::nitro::omni::MixAudioMode>>::toJSI(runtime, arg.mixAudio));
obj.setProperty(runtime, PropNameIDCache::get(runtime, "castData"), JSIConverter<std::optional<std::unordered_map<std::string, std::string>>>::toJSI(runtime, arg.castData));
return obj;
}
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
@@ -102,8 +110,10 @@ namespace margelo::nitro {
if (!JSIConverter<std::vector<margelo::nitro::omni::VideoSrc>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "src")))) return false;
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startTime")))) return false;
if (!JSIConverter<std::vector<margelo::nitro::omni::Subtitle>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "subtitles")))) return false;
if (!JSIConverter<std::optional<std::vector<std::string>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fonts")))) return false;
if (!JSIConverter<std::optional<margelo::nitro::omni::Metadata>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "metadata")))) return false;
if (!JSIConverter<std::optional<margelo::nitro::omni::MixAudioMode>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mixAudio")))) return false;
if (!JSIConverter<std::optional<std::unordered_map<std::string, std::string>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "castData")))) return false;
return true;
}
};
+92
View File
@@ -0,0 +1,92 @@
///
/// SubtitleAssets.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///
#pragma once
#if __has_include(<NitroModules/JSIConverter.hpp>)
#include <NitroModules/JSIConverter.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/NitroDefines.hpp>)
#include <NitroModules/NitroDefines.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/JSIHelpers.hpp>)
#include <NitroModules/JSIHelpers.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
#include <NitroModules/PropNameIDCache.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
// Forward declaration of `JassubAssets` to properly resolve imports.
namespace margelo::nitro::omni { struct JassubAssets; }
// Forward declaration of `PgsAssets` to properly resolve imports.
namespace margelo::nitro::omni { struct PgsAssets; }
#include "JassubAssets.hpp"
#include <optional>
#include "PgsAssets.hpp"
namespace margelo::nitro::omni {
/**
* A struct which can be represented as a JavaScript object (SubtitleAssets).
*/
struct SubtitleAssets final {
public:
std::optional<JassubAssets> jassub SWIFT_PRIVATE;
std::optional<PgsAssets> pgs SWIFT_PRIVATE;
public:
SubtitleAssets() = default;
explicit SubtitleAssets(std::optional<JassubAssets> jassub, std::optional<PgsAssets> pgs): jassub(jassub), pgs(pgs) {}
public:
friend bool operator==(const SubtitleAssets& lhs, const SubtitleAssets& rhs) = default;
};
} // namespace margelo::nitro::omni
namespace margelo::nitro {
// C++ SubtitleAssets <> JS SubtitleAssets (object)
template <>
struct JSIConverter<margelo::nitro::omni::SubtitleAssets> final {
static inline margelo::nitro::omni::SubtitleAssets fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
jsi::Object obj = arg.asObject(runtime);
return margelo::nitro::omni::SubtitleAssets(
JSIConverter<std::optional<margelo::nitro::omni::JassubAssets>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "jassub"))),
JSIConverter<std::optional<margelo::nitro::omni::PgsAssets>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "pgs")))
);
}
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::omni::SubtitleAssets& arg) {
jsi::Object obj(runtime);
obj.setProperty(runtime, PropNameIDCache::get(runtime, "jassub"), JSIConverter<std::optional<margelo::nitro::omni::JassubAssets>>::toJSI(runtime, arg.jassub));
obj.setProperty(runtime, PropNameIDCache::get(runtime, "pgs"), JSIConverter<std::optional<margelo::nitro::omni::PgsAssets>>::toJSI(runtime, arg.pgs));
return obj;
}
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
if (!value.isObject()) {
return false;
}
jsi::Object obj = value.getObject(runtime);
if (!nitro::isPlainObject(runtime, obj)) {
return false;
}
if (!JSIConverter<std::optional<margelo::nitro::omni::JassubAssets>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "jassub")))) return false;
if (!JSIConverter<std::optional<margelo::nitro::omni::PgsAssets>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "pgs")))) return false;
return true;
}
};
} // namespace margelo::nitro
@@ -56,6 +56,16 @@ namespace margelo::nitro::omni::views {
throw std::runtime_error(std::string("OmniView.autoPip: ") + exc.what());
}
}()),
subtitleAssets([&]() -> CachedProp<std::optional<SubtitleAssets>> {
try {
const react::RawValue* rawValue = rawProps.at("subtitleAssets", nullptr, nullptr);
if (rawValue == nullptr) return sourceProps.subtitleAssets;
const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
return CachedProp<std::optional<SubtitleAssets>>::fromRawValue(*runtime, value, sourceProps.subtitleAssets);
} catch (const std::exception& exc) {
throw std::runtime_error(std::string("OmniView.subtitleAssets: ") + exc.what());
}
}()),
hybridRef([&]() -> CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridOmniViewSpec>& /* ref */)>>> {
try {
const react::RawValue* rawValue = rawProps.at("hybridRef", nullptr, nullptr);
@@ -72,6 +82,7 @@ namespace margelo::nitro::omni::views {
case hashString("player"): return true;
case hashString("autoplay"): return true;
case hashString("autoPip"): return true;
case hashString("subtitleAssets"): return true;
case hashString("hybridRef"): return true;
default: return false;
}
@@ -79,7 +90,7 @@ namespace margelo::nitro::omni::views {
HybridOmniViewComponentDescriptor::HybridOmniViewComponentDescriptor(const react::ComponentDescriptorParameters& parameters)
: ConcreteComponentDescriptor(parameters,
react::RawPropsParser(/* enableJsiParser */ true)) {}
react::RawPropsParser()) {}
std::shared_ptr<const react::Props> HybridOmniViewComponentDescriptor::cloneProps(const react::PropsParserContext& context,
const std::shared_ptr<const react::Props>& props,
@@ -19,6 +19,7 @@
#include <memory>
#include "HybridOmniPlayerSpec.hpp"
#include <optional>
#include "SubtitleAssets.hpp"
#include "HybridOmniViewSpec.hpp"
#include <functional>
@@ -45,6 +46,7 @@ namespace margelo::nitro::omni::views {
CachedProp<std::shared_ptr<HybridOmniPlayerSpec>> player;
CachedProp<std::optional<bool>> autoplay;
CachedProp<std::optional<bool>> autoPip;
CachedProp<std::optional<SubtitleAssets>> subtitleAssets;
CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridOmniViewSpec>& /* ref */)>>> hybridRef;
private:
+1
View File
@@ -7,6 +7,7 @@
"player": true,
"autoplay": true,
"autoPip": true,
"subtitleAssets": true,
"hybridRef": true
}
}