react-native-nitro-web-image 0.5.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NitroWebImage.podspec +33 -0
- package/android/CMakeLists.txt +31 -0
- package/android/build.gradle +145 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/web/image/AsyncImagePriority+toCoroutineContext.kt +15 -0
- package/android/src/main/java/com/margelo/nitro/web/image/HybridWebImageFactory.kt +32 -0
- package/android/src/main/java/com/margelo/nitro/web/image/HybridWebImageLoader.kt +32 -0
- package/android/src/main/java/com/margelo/nitro/web/image/ImageLoader+loadImageAsync.kt +37 -0
- package/android/src/main/java/com/margelo/nitro/web/image/ImageRequestBuilder+applyOptions.kt +58 -0
- package/android/src/main/java/com/margelo/nitro/web/image/NitroWebImagePackage.java +44 -0
- package/ios/AsyncImageLoadOptions+toSDWebImageOptions.swift +66 -0
- package/ios/Bridge.h +8 -0
- package/ios/HybridWebImageFactory.swift +32 -0
- package/ios/HybridWebImageLoader.swift +54 -0
- package/ios/SDWebImageManager+loadImage.swift +30 -0
- package/lib/commonjs/index.js +9 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/specs/WebImageFactory.nitro.js +6 -0
- package/lib/commonjs/specs/WebImageFactory.nitro.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/specs/WebImageFactory.nitro.js +4 -0
- package/lib/module/specs/WebImageFactory.nitro.js.map +1 -0
- package/lib/tsconfig.build.tsbuildinfo +1 -0
- package/lib/typescript/index.d.ts +3 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/specs/WebImageFactory.nitro.d.ts +63 -0
- package/lib/typescript/specs/WebImageFactory.nitro.d.ts.map +1 -0
- package/nitro.json +18 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroWebImage+autolinking.cmake +78 -0
- package/nitrogen/generated/android/NitroWebImage+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroWebImageOnLoad.cpp +46 -0
- package/nitrogen/generated/android/NitroWebImageOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JAsyncImageLoadOptions.hpp +88 -0
- package/nitrogen/generated/android/c++/JAsyncImagePriority.hpp +62 -0
- package/nitrogen/generated/android/c++/JHybridWebImageFactorySpec.cpp +82 -0
- package/nitrogen/generated/android/c++/JHybridWebImageFactorySpec.hpp +64 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/web/image/AsyncImageLoadOptions.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/web/image/AsyncImagePriority.kt +26 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/web/image/HybridWebImageFactorySpec.kt +58 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/web/image/NitroWebImageOnLoad.kt +35 -0
- package/nitrogen/generated/ios/NitroWebImage+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroWebImage-Swift-Cxx-Bridge.cpp +65 -0
- package/nitrogen/generated/ios/NitroWebImage-Swift-Cxx-Bridge.hpp +197 -0
- package/nitrogen/generated/ios/NitroWebImage-Swift-Cxx-Umbrella.hpp +62 -0
- package/nitrogen/generated/ios/NitroWebImageAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroWebImageAutolinking.swift +25 -0
- package/nitrogen/generated/ios/c++/HybridWebImageFactorySpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridWebImageFactorySpecSwift.hpp +95 -0
- package/nitrogen/generated/ios/swift/AsyncImageLoadOptions.swift +237 -0
- package/nitrogen/generated/ios/swift/AsyncImagePriority.swift +44 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_margelo__nitro__image__HybridImageSpec_.swift +51 -0
- package/nitrogen/generated/ios/swift/HybridWebImageFactorySpec.swift +51 -0
- package/nitrogen/generated/ios/swift/HybridWebImageFactorySpec_cxx.swift +161 -0
- package/nitrogen/generated/shared/c++/AsyncImageLoadOptions.hpp +104 -0
- package/nitrogen/generated/shared/c++/AsyncImagePriority.hpp +82 -0
- package/nitrogen/generated/shared/c++/HybridWebImageFactorySpec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridWebImageFactorySpec.hpp +74 -0
- package/package.json +113 -0
- package/react-native.config.js +16 -0
- package/src/index.ts +5 -0
- package/src/specs/WebImageFactory.nitro.ts +76 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// AsyncImagePriority.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Represents the JS union `AsyncImagePriority`, backed by a C++ enum.
|
|
10
|
+
*/
|
|
11
|
+
public typealias AsyncImagePriority = margelo.nitro.web.image.AsyncImagePriority
|
|
12
|
+
|
|
13
|
+
public extension AsyncImagePriority {
|
|
14
|
+
/**
|
|
15
|
+
* Get a AsyncImagePriority for the given String value, or
|
|
16
|
+
* return `nil` if the given value was invalid/unknown.
|
|
17
|
+
*/
|
|
18
|
+
init?(fromString string: String) {
|
|
19
|
+
switch string {
|
|
20
|
+
case "low":
|
|
21
|
+
self = .low
|
|
22
|
+
case "default":
|
|
23
|
+
self = .default
|
|
24
|
+
case "high":
|
|
25
|
+
self = .high
|
|
26
|
+
default:
|
|
27
|
+
return nil
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get the String value this AsyncImagePriority represents.
|
|
33
|
+
*/
|
|
34
|
+
var stringValue: String {
|
|
35
|
+
switch self {
|
|
36
|
+
case .low:
|
|
37
|
+
return "low"
|
|
38
|
+
case .default:
|
|
39
|
+
return "default"
|
|
40
|
+
case .high:
|
|
41
|
+
return "high"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__exception_ptr.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Wraps a Swift `(_ error: Error) -> Void` as a class.
|
|
13
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
14
|
+
*/
|
|
15
|
+
public final class Func_void_std__exception_ptr {
|
|
16
|
+
public typealias bridge = margelo.nitro.web.image.bridge.swift
|
|
17
|
+
|
|
18
|
+
private let closure: (_ error: Error) -> Void
|
|
19
|
+
|
|
20
|
+
public init(_ closure: @escaping (_ error: Error) -> Void) {
|
|
21
|
+
self.closure = closure
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@inline(__always)
|
|
25
|
+
public func call(error: std.exception_ptr) -> Void {
|
|
26
|
+
self.closure(RuntimeError.from(cppError: error))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
31
|
+
* This acquires one additional strong reference on the object!
|
|
32
|
+
*/
|
|
33
|
+
@inline(__always)
|
|
34
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
35
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Casts an unsafe pointer to a `Func_void_std__exception_ptr`.
|
|
40
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__exception_ptr>`.
|
|
41
|
+
* This removes one strong reference from the object!
|
|
42
|
+
*/
|
|
43
|
+
@inline(__always)
|
|
44
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__exception_ptr {
|
|
45
|
+
return Unmanaged<Func_void_std__exception_ptr>.fromOpaque(pointer).takeRetainedValue()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__shared_ptr_margelo__nitro__image__HybridImageSpec_.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import NitroModules
|
|
9
|
+
import NitroImage
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Wraps a Swift `(_ value: (any HybridImageSpec)) -> Void` as a class.
|
|
13
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
14
|
+
*/
|
|
15
|
+
public final class Func_void_std__shared_ptr_margelo__nitro__image__HybridImageSpec_ {
|
|
16
|
+
public typealias bridge = margelo.nitro.web.image.bridge.swift
|
|
17
|
+
|
|
18
|
+
private let closure: (_ value: (any HybridImageSpec)) -> Void
|
|
19
|
+
|
|
20
|
+
public init(_ closure: @escaping (_ value: (any HybridImageSpec)) -> Void) {
|
|
21
|
+
self.closure = closure
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@inline(__always)
|
|
25
|
+
public func call(value: bridge.std__shared_ptr_margelo__nitro__image__HybridImageSpec_) -> Void {
|
|
26
|
+
self.closure({ () -> HybridImageSpec in
|
|
27
|
+
let __unsafePointer = bridge.get_std__shared_ptr_margelo__nitro__image__HybridImageSpec_(value)
|
|
28
|
+
let __instance = HybridImageSpec_cxx.fromUnsafe(__unsafePointer)
|
|
29
|
+
return __instance.getHybridImageSpec()
|
|
30
|
+
}())
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
35
|
+
* This acquires one additional strong reference on the object!
|
|
36
|
+
*/
|
|
37
|
+
@inline(__always)
|
|
38
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
39
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Casts an unsafe pointer to a `Func_void_std__shared_ptr_margelo__nitro__image__HybridImageSpec_`.
|
|
44
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__shared_ptr_margelo__nitro__image__HybridImageSpec_>`.
|
|
45
|
+
* This removes one strong reference from the object!
|
|
46
|
+
*/
|
|
47
|
+
@inline(__always)
|
|
48
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__shared_ptr_margelo__nitro__image__HybridImageSpec_ {
|
|
49
|
+
return Unmanaged<Func_void_std__shared_ptr_margelo__nitro__image__HybridImageSpec_>.fromOpaque(pointer).takeRetainedValue()
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridWebImageFactorySpec.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
import NitroImage
|
|
11
|
+
|
|
12
|
+
/// See ``HybridWebImageFactorySpec``
|
|
13
|
+
public protocol HybridWebImageFactorySpec_protocol: HybridObject {
|
|
14
|
+
// Properties
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
// Methods
|
|
18
|
+
func createWebImageLoader(url: String, options: AsyncImageLoadOptions?) throws -> (any HybridImageLoaderSpec)
|
|
19
|
+
func loadFromURLAsync(url: String, options: AsyncImageLoadOptions?) throws -> Promise<(any HybridImageSpec)>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/// See ``HybridWebImageFactorySpec``
|
|
23
|
+
open class HybridWebImageFactorySpec_base {
|
|
24
|
+
private weak var cxxWrapper: HybridWebImageFactorySpec_cxx? = nil
|
|
25
|
+
public init() { }
|
|
26
|
+
public func getCxxWrapper() -> HybridWebImageFactorySpec_cxx {
|
|
27
|
+
#if DEBUG
|
|
28
|
+
guard self is HybridWebImageFactorySpec else {
|
|
29
|
+
fatalError("`self` is not a `HybridWebImageFactorySpec`! Did you accidentally inherit from `HybridWebImageFactorySpec_base` instead of `HybridWebImageFactorySpec`?")
|
|
30
|
+
}
|
|
31
|
+
#endif
|
|
32
|
+
if let cxxWrapper = self.cxxWrapper {
|
|
33
|
+
return cxxWrapper
|
|
34
|
+
} else {
|
|
35
|
+
let cxxWrapper = HybridWebImageFactorySpec_cxx(self as! HybridWebImageFactorySpec)
|
|
36
|
+
self.cxxWrapper = cxxWrapper
|
|
37
|
+
return cxxWrapper
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A Swift base-protocol representing the WebImageFactory HybridObject.
|
|
44
|
+
* Implement this protocol to create Swift-based instances of WebImageFactory.
|
|
45
|
+
* ```swift
|
|
46
|
+
* class HybridWebImageFactory : HybridWebImageFactorySpec {
|
|
47
|
+
* // ...
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
public typealias HybridWebImageFactorySpec = HybridWebImageFactorySpec_protocol & HybridWebImageFactorySpec_base
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridWebImageFactorySpec_cxx.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
import NitroImage
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A class implementation that bridges HybridWebImageFactorySpec over to C++.
|
|
14
|
+
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
|
|
15
|
+
*
|
|
16
|
+
* Also, some Swift types need to be bridged with special handling:
|
|
17
|
+
* - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
|
|
18
|
+
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
|
|
19
|
+
* - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
|
|
20
|
+
*/
|
|
21
|
+
open class HybridWebImageFactorySpec_cxx {
|
|
22
|
+
/**
|
|
23
|
+
* The Swift <> C++ bridge's namespace (`margelo::nitro::web::image::bridge::swift`)
|
|
24
|
+
* from `NitroWebImage-Swift-Cxx-Bridge.hpp`.
|
|
25
|
+
* This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
|
|
26
|
+
*/
|
|
27
|
+
public typealias bridge = margelo.nitro.web.image.bridge.swift
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Holds an instance of the `HybridWebImageFactorySpec` Swift protocol.
|
|
31
|
+
*/
|
|
32
|
+
private var __implementation: any HybridWebImageFactorySpec
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Holds a weak pointer to the C++ class that wraps the Swift class.
|
|
36
|
+
*/
|
|
37
|
+
private var __cxxPart: bridge.std__weak_ptr_margelo__nitro__web__image__HybridWebImageFactorySpec_
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Create a new `HybridWebImageFactorySpec_cxx` that wraps the given `HybridWebImageFactorySpec`.
|
|
41
|
+
* All properties and methods bridge to C++ types.
|
|
42
|
+
*/
|
|
43
|
+
public init(_ implementation: any HybridWebImageFactorySpec) {
|
|
44
|
+
self.__implementation = implementation
|
|
45
|
+
self.__cxxPart = .init()
|
|
46
|
+
/* no base class */
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get the actual `HybridWebImageFactorySpec` instance this class wraps.
|
|
51
|
+
*/
|
|
52
|
+
@inline(__always)
|
|
53
|
+
public func getHybridWebImageFactorySpec() -> any HybridWebImageFactorySpec {
|
|
54
|
+
return __implementation
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
59
|
+
* This acquires one additional strong reference on the object!
|
|
60
|
+
*/
|
|
61
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
62
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Casts an unsafe pointer to a `HybridWebImageFactorySpec_cxx`.
|
|
67
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridWebImageFactorySpec_cxx>`.
|
|
68
|
+
* This removes one strong reference from the object!
|
|
69
|
+
*/
|
|
70
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridWebImageFactorySpec_cxx {
|
|
71
|
+
return Unmanaged<HybridWebImageFactorySpec_cxx>.fromOpaque(pointer).takeRetainedValue()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Gets (or creates) the C++ part of this Hybrid Object.
|
|
76
|
+
* The C++ part is a `std::shared_ptr<margelo::nitro::web::image::HybridWebImageFactorySpec>`.
|
|
77
|
+
*/
|
|
78
|
+
public func getCxxPart() -> bridge.std__shared_ptr_margelo__nitro__web__image__HybridWebImageFactorySpec_ {
|
|
79
|
+
let cachedCxxPart = self.__cxxPart.lock()
|
|
80
|
+
if cachedCxxPart.__convertToBool() {
|
|
81
|
+
return cachedCxxPart
|
|
82
|
+
} else {
|
|
83
|
+
let newCxxPart = bridge.create_std__shared_ptr_margelo__nitro__web__image__HybridWebImageFactorySpec_(self.toUnsafe())
|
|
84
|
+
__cxxPart = bridge.weakify_std__shared_ptr_margelo__nitro__web__image__HybridWebImageFactorySpec_(newCxxPart)
|
|
85
|
+
return newCxxPart
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Get the memory size of the Swift class (plus size of any other allocations)
|
|
93
|
+
* so the JS VM can properly track it and garbage-collect the JS object if needed.
|
|
94
|
+
*/
|
|
95
|
+
@inline(__always)
|
|
96
|
+
public var memorySize: Int {
|
|
97
|
+
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Call dispose() on the Swift class.
|
|
102
|
+
* This _may_ be called manually from JS.
|
|
103
|
+
*/
|
|
104
|
+
@inline(__always)
|
|
105
|
+
public func dispose() {
|
|
106
|
+
self.__implementation.dispose()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Properties
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
// Methods
|
|
113
|
+
@inline(__always)
|
|
114
|
+
public final func createWebImageLoader(url: std.string, options: bridge.std__optional_AsyncImageLoadOptions_) -> bridge.Result_std__shared_ptr_margelo__nitro__image__HybridImageLoaderSpec__ {
|
|
115
|
+
do {
|
|
116
|
+
let __result = try self.__implementation.createWebImageLoader(url: String(url), options: { () -> AsyncImageLoadOptions? in
|
|
117
|
+
if let __unwrapped = options.value {
|
|
118
|
+
return __unwrapped
|
|
119
|
+
} else {
|
|
120
|
+
return nil
|
|
121
|
+
}
|
|
122
|
+
}())
|
|
123
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_margelo__nitro__image__HybridImageLoaderSpec_ in
|
|
124
|
+
let __cxxWrapped = __result.getCxxWrapper()
|
|
125
|
+
return __cxxWrapped.getCxxPart()
|
|
126
|
+
}()
|
|
127
|
+
return bridge.create_Result_std__shared_ptr_margelo__nitro__image__HybridImageLoaderSpec__(__resultCpp)
|
|
128
|
+
} catch (let __error) {
|
|
129
|
+
let __exceptionPtr = __error.toCpp()
|
|
130
|
+
return bridge.create_Result_std__shared_ptr_margelo__nitro__image__HybridImageLoaderSpec__(__exceptionPtr)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@inline(__always)
|
|
135
|
+
public final func loadFromURLAsync(url: std.string, options: bridge.std__optional_AsyncImageLoadOptions_) -> bridge.Result_std__shared_ptr_Promise_std__shared_ptr_margelo__nitro__image__HybridImageSpec____ {
|
|
136
|
+
do {
|
|
137
|
+
let __result = try self.__implementation.loadFromURLAsync(url: String(url), options: { () -> AsyncImageLoadOptions? in
|
|
138
|
+
if let __unwrapped = options.value {
|
|
139
|
+
return __unwrapped
|
|
140
|
+
} else {
|
|
141
|
+
return nil
|
|
142
|
+
}
|
|
143
|
+
}())
|
|
144
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__shared_ptr_margelo__nitro__image__HybridImageSpec___ in
|
|
145
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_margelo__nitro__image__HybridImageSpec___()
|
|
146
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_margelo__nitro__image__HybridImageSpec___(__promise)
|
|
147
|
+
__result
|
|
148
|
+
.then({ __result in __promiseHolder.resolve({ () -> bridge.std__shared_ptr_margelo__nitro__image__HybridImageSpec_ in
|
|
149
|
+
let __cxxWrapped = __result.getCxxWrapper()
|
|
150
|
+
return __cxxWrapped.getCxxPart()
|
|
151
|
+
}()) })
|
|
152
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
153
|
+
return __promise
|
|
154
|
+
}()
|
|
155
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__shared_ptr_margelo__nitro__image__HybridImageSpec____(__resultCpp)
|
|
156
|
+
} catch (let __error) {
|
|
157
|
+
let __exceptionPtr = __error.toCpp()
|
|
158
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__shared_ptr_margelo__nitro__image__HybridImageSpec____(__exceptionPtr)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// AsyncImageLoadOptions.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
// Forward declaration of `AsyncImagePriority` to properly resolve imports.
|
|
22
|
+
namespace margelo::nitro::web::image { enum class AsyncImagePriority; }
|
|
23
|
+
|
|
24
|
+
#include "AsyncImagePriority.hpp"
|
|
25
|
+
#include <optional>
|
|
26
|
+
#include <string>
|
|
27
|
+
|
|
28
|
+
namespace margelo::nitro::web::image {
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A struct which can be represented as a JavaScript object (AsyncImageLoadOptions).
|
|
32
|
+
*/
|
|
33
|
+
struct AsyncImageLoadOptions {
|
|
34
|
+
public:
|
|
35
|
+
std::optional<AsyncImagePriority> priority SWIFT_PRIVATE;
|
|
36
|
+
std::optional<bool> forceRefresh SWIFT_PRIVATE;
|
|
37
|
+
std::optional<std::string> cacheKey SWIFT_PRIVATE;
|
|
38
|
+
std::optional<bool> continueInBackground SWIFT_PRIVATE;
|
|
39
|
+
std::optional<bool> allowInvalidSSLCertificates SWIFT_PRIVATE;
|
|
40
|
+
std::optional<bool> scaleDownLargeImages SWIFT_PRIVATE;
|
|
41
|
+
std::optional<bool> queryMemoryDataSync SWIFT_PRIVATE;
|
|
42
|
+
std::optional<bool> queryDiskDataSync SWIFT_PRIVATE;
|
|
43
|
+
std::optional<bool> decodeImage SWIFT_PRIVATE;
|
|
44
|
+
|
|
45
|
+
public:
|
|
46
|
+
AsyncImageLoadOptions() = default;
|
|
47
|
+
explicit AsyncImageLoadOptions(std::optional<AsyncImagePriority> priority, std::optional<bool> forceRefresh, std::optional<std::string> cacheKey, std::optional<bool> continueInBackground, std::optional<bool> allowInvalidSSLCertificates, std::optional<bool> scaleDownLargeImages, std::optional<bool> queryMemoryDataSync, std::optional<bool> queryDiskDataSync, std::optional<bool> decodeImage): priority(priority), forceRefresh(forceRefresh), cacheKey(cacheKey), continueInBackground(continueInBackground), allowInvalidSSLCertificates(allowInvalidSSLCertificates), scaleDownLargeImages(scaleDownLargeImages), queryMemoryDataSync(queryMemoryDataSync), queryDiskDataSync(queryDiskDataSync), decodeImage(decodeImage) {}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
} // namespace margelo::nitro::web::image
|
|
51
|
+
|
|
52
|
+
namespace margelo::nitro {
|
|
53
|
+
|
|
54
|
+
using namespace margelo::nitro::web::image;
|
|
55
|
+
|
|
56
|
+
// C++ AsyncImageLoadOptions <> JS AsyncImageLoadOptions (object)
|
|
57
|
+
template <>
|
|
58
|
+
struct JSIConverter<AsyncImageLoadOptions> final {
|
|
59
|
+
static inline AsyncImageLoadOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
60
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
61
|
+
return AsyncImageLoadOptions(
|
|
62
|
+
JSIConverter<std::optional<AsyncImagePriority>>::fromJSI(runtime, obj.getProperty(runtime, "priority")),
|
|
63
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "forceRefresh")),
|
|
64
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "cacheKey")),
|
|
65
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "continueInBackground")),
|
|
66
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "allowInvalidSSLCertificates")),
|
|
67
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "scaleDownLargeImages")),
|
|
68
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "queryMemoryDataSync")),
|
|
69
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "queryDiskDataSync")),
|
|
70
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "decodeImage"))
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const AsyncImageLoadOptions& arg) {
|
|
74
|
+
jsi::Object obj(runtime);
|
|
75
|
+
obj.setProperty(runtime, "priority", JSIConverter<std::optional<AsyncImagePriority>>::toJSI(runtime, arg.priority));
|
|
76
|
+
obj.setProperty(runtime, "forceRefresh", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.forceRefresh));
|
|
77
|
+
obj.setProperty(runtime, "cacheKey", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.cacheKey));
|
|
78
|
+
obj.setProperty(runtime, "continueInBackground", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.continueInBackground));
|
|
79
|
+
obj.setProperty(runtime, "allowInvalidSSLCertificates", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.allowInvalidSSLCertificates));
|
|
80
|
+
obj.setProperty(runtime, "scaleDownLargeImages", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.scaleDownLargeImages));
|
|
81
|
+
obj.setProperty(runtime, "queryMemoryDataSync", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.queryMemoryDataSync));
|
|
82
|
+
obj.setProperty(runtime, "queryDiskDataSync", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.queryDiskDataSync));
|
|
83
|
+
obj.setProperty(runtime, "decodeImage", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.decodeImage));
|
|
84
|
+
return obj;
|
|
85
|
+
}
|
|
86
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
87
|
+
if (!value.isObject()) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
jsi::Object obj = value.getObject(runtime);
|
|
91
|
+
if (!JSIConverter<std::optional<AsyncImagePriority>>::canConvert(runtime, obj.getProperty(runtime, "priority"))) return false;
|
|
92
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "forceRefresh"))) return false;
|
|
93
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "cacheKey"))) return false;
|
|
94
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "continueInBackground"))) return false;
|
|
95
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "allowInvalidSSLCertificates"))) return false;
|
|
96
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "scaleDownLargeImages"))) return false;
|
|
97
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "queryMemoryDataSync"))) return false;
|
|
98
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "queryDiskDataSync"))) return false;
|
|
99
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "decodeImage"))) return false;
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// AsyncImagePriority.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/NitroHash.hpp>)
|
|
11
|
+
#include <NitroModules/NitroHash.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
16
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
21
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::web::image {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (AsyncImagePriority).
|
|
30
|
+
*/
|
|
31
|
+
enum class AsyncImagePriority {
|
|
32
|
+
LOW SWIFT_NAME(low) = 0,
|
|
33
|
+
DEFAULT SWIFT_NAME(default) = 1,
|
|
34
|
+
HIGH SWIFT_NAME(high) = 2,
|
|
35
|
+
} CLOSED_ENUM;
|
|
36
|
+
|
|
37
|
+
} // namespace margelo::nitro::web::image
|
|
38
|
+
|
|
39
|
+
namespace margelo::nitro {
|
|
40
|
+
|
|
41
|
+
using namespace margelo::nitro::web::image;
|
|
42
|
+
|
|
43
|
+
// C++ AsyncImagePriority <> JS AsyncImagePriority (union)
|
|
44
|
+
template <>
|
|
45
|
+
struct JSIConverter<AsyncImagePriority> final {
|
|
46
|
+
static inline AsyncImagePriority fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
47
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
48
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
49
|
+
case hashString("low"): return AsyncImagePriority::LOW;
|
|
50
|
+
case hashString("default"): return AsyncImagePriority::DEFAULT;
|
|
51
|
+
case hashString("high"): return AsyncImagePriority::HIGH;
|
|
52
|
+
default: [[unlikely]]
|
|
53
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum AsyncImagePriority - invalid value!");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, AsyncImagePriority arg) {
|
|
57
|
+
switch (arg) {
|
|
58
|
+
case AsyncImagePriority::LOW: return JSIConverter<std::string>::toJSI(runtime, "low");
|
|
59
|
+
case AsyncImagePriority::DEFAULT: return JSIConverter<std::string>::toJSI(runtime, "default");
|
|
60
|
+
case AsyncImagePriority::HIGH: return JSIConverter<std::string>::toJSI(runtime, "high");
|
|
61
|
+
default: [[unlikely]]
|
|
62
|
+
throw std::invalid_argument("Cannot convert AsyncImagePriority to JS - invalid value: "
|
|
63
|
+
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
67
|
+
if (!value.isString()) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
71
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
72
|
+
case hashString("low"):
|
|
73
|
+
case hashString("default"):
|
|
74
|
+
case hashString("high"):
|
|
75
|
+
return true;
|
|
76
|
+
default:
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridWebImageFactorySpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridWebImageFactorySpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::web::image {
|
|
11
|
+
|
|
12
|
+
void HybridWebImageFactorySpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("createWebImageLoader", &HybridWebImageFactorySpec::createWebImageLoader);
|
|
18
|
+
prototype.registerHybridMethod("loadFromURLAsync", &HybridWebImageFactorySpec::loadFromURLAsync);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
} // namespace margelo::nitro::web::image
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridWebImageFactorySpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `HybridImageLoaderSpec` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::image { class HybridImageLoaderSpec; }
|
|
18
|
+
// Forward declaration of `AsyncImageLoadOptions` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::web::image { struct AsyncImageLoadOptions; }
|
|
20
|
+
// Forward declaration of `HybridImageSpec` to properly resolve imports.
|
|
21
|
+
namespace margelo::nitro::image { class HybridImageSpec; }
|
|
22
|
+
|
|
23
|
+
#include <memory>
|
|
24
|
+
#include <NitroImage/HybridImageLoaderSpec.hpp>
|
|
25
|
+
#include <string>
|
|
26
|
+
#include "AsyncImageLoadOptions.hpp"
|
|
27
|
+
#include <optional>
|
|
28
|
+
#include <NitroImage/HybridImageSpec.hpp>
|
|
29
|
+
#include <NitroModules/Promise.hpp>
|
|
30
|
+
|
|
31
|
+
namespace margelo::nitro::web::image {
|
|
32
|
+
|
|
33
|
+
using namespace margelo::nitro;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* An abstract base class for `WebImageFactory`
|
|
37
|
+
* Inherit this class to create instances of `HybridWebImageFactorySpec` in C++.
|
|
38
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
39
|
+
* @example
|
|
40
|
+
* ```cpp
|
|
41
|
+
* class HybridWebImageFactory: public HybridWebImageFactorySpec {
|
|
42
|
+
* public:
|
|
43
|
+
* HybridWebImageFactory(...): HybridObject(TAG) { ... }
|
|
44
|
+
* // ...
|
|
45
|
+
* };
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
class HybridWebImageFactorySpec: public virtual HybridObject {
|
|
49
|
+
public:
|
|
50
|
+
// Constructor
|
|
51
|
+
explicit HybridWebImageFactorySpec(): HybridObject(TAG) { }
|
|
52
|
+
|
|
53
|
+
// Destructor
|
|
54
|
+
~HybridWebImageFactorySpec() override = default;
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
// Properties
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
public:
|
|
61
|
+
// Methods
|
|
62
|
+
virtual std::shared_ptr<margelo::nitro::image::HybridImageLoaderSpec> createWebImageLoader(const std::string& url, const std::optional<AsyncImageLoadOptions>& options) = 0;
|
|
63
|
+
virtual std::shared_ptr<Promise<std::shared_ptr<margelo::nitro::image::HybridImageSpec>>> loadFromURLAsync(const std::string& url, const std::optional<AsyncImageLoadOptions>& options) = 0;
|
|
64
|
+
|
|
65
|
+
protected:
|
|
66
|
+
// Hybrid Setup
|
|
67
|
+
void loadHybridMethods() override;
|
|
68
|
+
|
|
69
|
+
protected:
|
|
70
|
+
// Tag for logging
|
|
71
|
+
static constexpr auto TAG = "WebImageFactory";
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
} // namespace margelo::nitro::web::image
|