-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement a bunch of Swift types
- Loading branch information
Showing
16 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/react-native-nitro-image/nitrogen/generated/ios/c++/HybridImage.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/// | ||
/// HybridImage.cpp | ||
/// Fri Jul 19 2024 | ||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. | ||
/// https://github.com/mrousavy/react-native-nitro | ||
/// Copyright © 2024 Marc Rousavy @ Margelo | ||
/// | ||
|
||
#include "HybridImage.hpp" | ||
|
||
void HybridImage::loadHybridMethods() { | ||
// load base methods/properties | ||
HybridObject::loadHybridMethods(); | ||
// load custom methods/properties | ||
registerHybridGetter("width", &HybridImage::getWidth, this); | ||
registerHybridGetter("height", &HybridImage::getHeight, this); | ||
registerHybridGetter("pixelFormat", &HybridImage::getPixelFormat, this); | ||
registerHybridMethod("toArrayBuffer", &HybridImage::toArrayBuffer, this); | ||
registerHybridMethod("saveToFile", &HybridImage::saveToFile, this); | ||
} |
55 changes: 55 additions & 0 deletions
55
packages/react-native-nitro-image/nitrogen/generated/ios/c++/HybridImage.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/// | ||
/// HybridImage.hpp | ||
/// Fri Jul 19 2024 | ||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. | ||
/// https://github.com/mrousavy/react-native-nitro | ||
/// Copyright © 2024 Marc Rousavy @ Margelo | ||
/// | ||
|
||
#pragma once | ||
|
||
#if __has_include(<NitroModules/HybridObject.hpp>) | ||
#include <NitroModules/HybridObject.hpp> | ||
#else | ||
#error NitroModules cannot be found! Are you sure you installed react-native-nitro properly? | ||
#endif | ||
|
||
#include "PixelFormat.hpp" | ||
#include "ImageFormat.hpp" | ||
|
||
using namespace margelo::nitro; | ||
|
||
/** | ||
* An abstract base class for `Image` | ||
* Inherit this class to create instances of `HybridImage` in C++. | ||
* @example | ||
* ```cpp | ||
* class Image: public HybridImage { | ||
* // ... | ||
* }; | ||
* ``` | ||
*/ | ||
class HybridImage: public HybridObject { | ||
public: | ||
// Constructor | ||
explicit HybridImage(): HybridObject(TAG) { } | ||
|
||
public: | ||
// Properties | ||
virtual double getWidth() = 0; | ||
virtual double getHeight() = 0; | ||
virtual PixelFormat getPixelFormat() = 0; | ||
|
||
public: | ||
// Methods | ||
virtual std::shared_ptr<ArrayBuffer> toArrayBuffer(ImageFormat format) = 0; | ||
virtual std::future<void> saveToFile(const std::string& path) = 0; | ||
|
||
protected: | ||
// Tag for logging | ||
static constexpr auto TAG = "Image"; | ||
|
||
private: | ||
// Hybrid Setup | ||
void loadHybridMethods() override; | ||
}; |
44 changes: 44 additions & 0 deletions
44
packages/react-native-nitro-image/nitrogen/generated/ios/c++/ImageFormat.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/// | ||
/// ImageFormat.hpp | ||
/// Fri Jul 19 2024 | ||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. | ||
/// https://github.com/mrousavy/react-native-nitro | ||
/// Copyright © 2024 Marc Rousavy @ Margelo | ||
/// | ||
|
||
#pragma once | ||
|
||
#include <NitroModules/Hash.hpp> | ||
#include <NitroModules/JSIConverter.hpp> | ||
|
||
enum class ImageFormat { | ||
jpg, | ||
png, | ||
} __attribute__((enum_extensibility(closed))); | ||
|
||
namespace margelo::nitro { | ||
|
||
// C++ ImageFormat <> JS ImageFormat (union) | ||
template <> | ||
struct JSIConverter<ImageFormat> { | ||
static inline ImageFormat 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("jpg"): return ImageFormat::jpg; | ||
case hashString("png"): return ImageFormat::png; | ||
default: [[unlikely]] | ||
throw std::runtime_error("Cannot convert " + unionValue + " to ImageFormat - invalid value!"); | ||
} | ||
} | ||
static inline jsi::Value toJSI(jsi::Runtime& runtime, ImageFormat arg) { | ||
switch (arg) { | ||
case ImageFormat::jpg: return JSIConverter<std::string>::toJSI(runtime, "jpg"); | ||
case ImageFormat::png: return JSIConverter<std::string>::toJSI(runtime, "png"); | ||
default: [[unlikely]] | ||
throw std::runtime_error("Cannot convert ImageFormat to JS - invalid value: " | ||
+ std::to_string(static_cast<int>(arg)) + "!"); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace margelo::nitro |
47 changes: 47 additions & 0 deletions
47
packages/react-native-nitro-image/nitrogen/generated/ios/c++/PixelFormat.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/// | ||
/// PixelFormat.hpp | ||
/// Fri Jul 19 2024 | ||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. | ||
/// https://github.com/mrousavy/react-native-nitro | ||
/// Copyright © 2024 Marc Rousavy @ Margelo | ||
/// | ||
|
||
#pragma once | ||
|
||
#include <NitroModules/Hash.hpp> | ||
#include <NitroModules/JSIConverter.hpp> | ||
|
||
enum class PixelFormat { | ||
rgb, | ||
yuv_8bit, | ||
yuv_10bit, | ||
} __attribute__((enum_extensibility(closed))); | ||
|
||
namespace margelo::nitro { | ||
|
||
// C++ PixelFormat <> JS PixelFormat (union) | ||
template <> | ||
struct JSIConverter<PixelFormat> { | ||
static inline PixelFormat 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("rgb"): return PixelFormat::rgb; | ||
case hashString("yuv-8bit"): return PixelFormat::yuv_8bit; | ||
case hashString("yuv-10bit"): return PixelFormat::yuv_10bit; | ||
default: [[unlikely]] | ||
throw std::runtime_error("Cannot convert " + unionValue + " to PixelFormat - invalid value!"); | ||
} | ||
} | ||
static inline jsi::Value toJSI(jsi::Runtime& runtime, PixelFormat arg) { | ||
switch (arg) { | ||
case PixelFormat::rgb: return JSIConverter<std::string>::toJSI(runtime, "rgb"); | ||
case PixelFormat::yuv_8bit: return JSIConverter<std::string>::toJSI(runtime, "yuv-8bit"); | ||
case PixelFormat::yuv_10bit: return JSIConverter<std::string>::toJSI(runtime, "yuv-10bit"); | ||
default: [[unlikely]] | ||
throw std::runtime_error("Cannot convert PixelFormat to JS - invalid value: " | ||
+ std::to_string(static_cast<int>(arg)) + "!"); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace margelo::nitro |
20 changes: 20 additions & 0 deletions
20
packages/react-native-nitro-image/nitrogen/generated/ios/swift/Image.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/// | ||
/// Image.swift | ||
/// Fri Jul 19 2024 | ||
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. | ||
/// https://github.com/mrousavy/react-native-nitro | ||
/// Copyright © 2024 Marc Rousavy @ Margelo | ||
/// | ||
|
||
import Foundation | ||
|
||
public protocol Image { | ||
// Properties | ||
public var width: Double { get } | ||
public var height: Double { get } | ||
public var pixelFormat: PixelFormat { get } | ||
|
||
// Methods | ||
public func toArrayBuffer(format: ImageFormat) throws -> Data | ||
public func saveToFile(path: String) throws -> Promise<Void> | ||
} |