@rive-app/react-native 0.2.5 → 0.2.7
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/android/src/main/java/com/margelo/nitro/rive/{Rive.kt → HybridDefaultFallbackFont.kt} +1 -5
- package/android/src/main/java/com/margelo/nitro/rive/HybridFallbackFont.kt +10 -0
- package/android/src/main/java/com/margelo/nitro/rive/HybridRiveFontConfig.kt +136 -0
- package/ios/HybridDefaultFallbackFont.swift +3 -0
- package/ios/HybridFallbackFont.swift +10 -0
- package/ios/HybridRiveFontConfig.swift +109 -0
- package/lib/module/core/RiveFonts.js +72 -0
- package/lib/module/core/RiveFonts.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/RiveFontConfig.nitro.js +4 -0
- package/lib/module/specs/{Rive.nitro.js.map → RiveFontConfig.nitro.js.map} +1 -1
- package/lib/typescript/src/core/RiveFonts.d.ts +23 -0
- package/lib/typescript/src/core/RiveFonts.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/RiveFontConfig.nitro.d.ts +20 -0
- package/lib/typescript/src/specs/RiveFontConfig.nitro.d.ts.map +1 -0
- package/nitrogen/generated/android/c++/JHybridFallbackFontSpec.cpp +55 -0
- package/nitrogen/generated/android/c++/{JHybridRiveSpec.hpp → JHybridFallbackFontSpec.hpp} +11 -11
- package/nitrogen/generated/android/c++/JHybridRiveFontConfigSpec.cpp +143 -0
- package/nitrogen/generated/android/c++/JHybridRiveFontConfigSpec.hpp +73 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/{HybridRiveSpec.kt → HybridFallbackFontSpec.kt} +7 -9
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/HybridRiveFontConfigSpec.kt +87 -0
- package/nitrogen/generated/android/rive+autolinking.cmake +4 -2
- package/nitrogen/generated/android/riveOnLoad.cpp +6 -4
- package/nitrogen/generated/ios/RNRive-Swift-Cxx-Bridge.cpp +50 -25
- package/nitrogen/generated/ios/RNRive-Swift-Cxx-Bridge.hpp +149 -69
- package/nitrogen/generated/ios/RNRive-Swift-Cxx-Umbrella.hpp +10 -5
- package/nitrogen/generated/ios/RNRiveAutolinking.mm +3 -3
- package/nitrogen/generated/ios/RNRiveAutolinking.swift +5 -5
- package/nitrogen/generated/ios/c++/{HybridRiveSpecSwift.cpp → HybridFallbackFontSpecSwift.cpp} +2 -2
- package/nitrogen/generated/ios/c++/{HybridRiveSpecSwift.hpp → HybridFallbackFontSpecSwift.hpp} +14 -21
- package/nitrogen/generated/ios/c++/HybridRiveFontConfigSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridRiveFontConfigSpecSwift.hpp +145 -0
- package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_HybridFallbackFontSpec_.swift +51 -0
- package/nitrogen/generated/ios/swift/HybridFallbackFontSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/{HybridRiveSpec_cxx.swift → HybridFallbackFontSpec_cxx.swift} +20 -30
- package/nitrogen/generated/ios/swift/HybridRiveFontConfigSpec.swift +63 -0
- package/nitrogen/generated/ios/swift/HybridRiveFontConfigSpec_cxx.swift +262 -0
- package/nitrogen/generated/shared/c++/{HybridRiveSpec.cpp → HybridFallbackFontSpec.cpp} +4 -4
- package/nitrogen/generated/shared/c++/{HybridRiveSpec.hpp → HybridFallbackFontSpec.hpp} +10 -10
- package/nitrogen/generated/shared/c++/HybridRiveFontConfigSpec.cpp +28 -0
- package/nitrogen/generated/shared/c++/HybridRiveFontConfigSpec.hpp +75 -0
- package/package.json +3 -3
- package/src/core/RiveFonts.ts +95 -0
- package/src/index.tsx +7 -0
- package/src/specs/RiveFontConfig.nitro.ts +16 -0
- package/ios/Rive.swift +0 -5
- package/lib/module/specs/Rive.nitro.js +0 -4
- package/lib/typescript/src/specs/Rive.nitro.d.ts +0 -8
- package/lib/typescript/src/specs/Rive.nitro.d.ts.map +0 -1
- package/nitrogen/generated/android/c++/JHybridRiveSpec.cpp +0 -59
- package/nitrogen/generated/ios/swift/HybridRiveSpec.swift +0 -56
- package/src/specs/Rive.nitro.ts +0 -6
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridRiveFontConfigSpec_cxx.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A class implementation that bridges HybridRiveFontConfigSpec over to C++.
|
|
13
|
+
* In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
|
|
14
|
+
*
|
|
15
|
+
* Also, some Swift types need to be bridged with special handling:
|
|
16
|
+
* - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
|
|
17
|
+
* - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
|
|
18
|
+
* - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
|
|
19
|
+
*/
|
|
20
|
+
open class HybridRiveFontConfigSpec_cxx {
|
|
21
|
+
/**
|
|
22
|
+
* The Swift <> C++ bridge's namespace (`margelo::nitro::rive::bridge::swift`)
|
|
23
|
+
* from `RNRive-Swift-Cxx-Bridge.hpp`.
|
|
24
|
+
* This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
|
|
25
|
+
*/
|
|
26
|
+
public typealias bridge = margelo.nitro.rive.bridge.swift
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Holds an instance of the `HybridRiveFontConfigSpec` Swift protocol.
|
|
30
|
+
*/
|
|
31
|
+
private var __implementation: any HybridRiveFontConfigSpec
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Holds a weak pointer to the C++ class that wraps the Swift class.
|
|
35
|
+
*/
|
|
36
|
+
private var __cxxPart: bridge.std__weak_ptr_HybridRiveFontConfigSpec_
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a new `HybridRiveFontConfigSpec_cxx` that wraps the given `HybridRiveFontConfigSpec`.
|
|
40
|
+
* All properties and methods bridge to C++ types.
|
|
41
|
+
*/
|
|
42
|
+
public init(_ implementation: any HybridRiveFontConfigSpec) {
|
|
43
|
+
self.__implementation = implementation
|
|
44
|
+
self.__cxxPart = .init()
|
|
45
|
+
/* no base class */
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the actual `HybridRiveFontConfigSpec` instance this class wraps.
|
|
50
|
+
*/
|
|
51
|
+
@inline(__always)
|
|
52
|
+
public func getHybridRiveFontConfigSpec() -> any HybridRiveFontConfigSpec {
|
|
53
|
+
return __implementation
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
58
|
+
* This acquires one additional strong reference on the object!
|
|
59
|
+
*/
|
|
60
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
61
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Casts an unsafe pointer to a `HybridRiveFontConfigSpec_cxx`.
|
|
66
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridRiveFontConfigSpec_cxx>`.
|
|
67
|
+
* This removes one strong reference from the object!
|
|
68
|
+
*/
|
|
69
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridRiveFontConfigSpec_cxx {
|
|
70
|
+
return Unmanaged<HybridRiveFontConfigSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets (or creates) the C++ part of this Hybrid Object.
|
|
75
|
+
* The C++ part is a `std::shared_ptr<HybridRiveFontConfigSpec>`.
|
|
76
|
+
*/
|
|
77
|
+
public func getCxxPart() -> bridge.std__shared_ptr_HybridRiveFontConfigSpec_ {
|
|
78
|
+
let cachedCxxPart = self.__cxxPart.lock()
|
|
79
|
+
if Bool(fromCxx: cachedCxxPart) {
|
|
80
|
+
return cachedCxxPart
|
|
81
|
+
} else {
|
|
82
|
+
let newCxxPart = bridge.create_std__shared_ptr_HybridRiveFontConfigSpec_(self.toUnsafe())
|
|
83
|
+
__cxxPart = bridge.weakify_std__shared_ptr_HybridRiveFontConfigSpec_(newCxxPart)
|
|
84
|
+
return newCxxPart
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get the memory size of the Swift class (plus size of any other allocations)
|
|
92
|
+
* so the JS VM can properly track it and garbage-collect the JS object if needed.
|
|
93
|
+
*/
|
|
94
|
+
@inline(__always)
|
|
95
|
+
public var memorySize: Int {
|
|
96
|
+
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Compares this object with the given [other] object for reference equality.
|
|
101
|
+
*/
|
|
102
|
+
@inline(__always)
|
|
103
|
+
public func equals(other: HybridRiveFontConfigSpec_cxx) -> Bool {
|
|
104
|
+
return self.__implementation === other.__implementation
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Call dispose() on the Swift class.
|
|
109
|
+
* This _may_ be called manually from JS.
|
|
110
|
+
*/
|
|
111
|
+
@inline(__always)
|
|
112
|
+
public func dispose() {
|
|
113
|
+
self.__implementation.dispose()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Call toString() on the Swift class.
|
|
118
|
+
*/
|
|
119
|
+
@inline(__always)
|
|
120
|
+
public func toString() -> String {
|
|
121
|
+
return self.__implementation.toString()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Properties
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
// Methods
|
|
128
|
+
@inline(__always)
|
|
129
|
+
public final func loadFontFromURL(url: std.string) -> bridge.Result_std__shared_ptr_Promise_std__shared_ptr_HybridFallbackFontSpec____ {
|
|
130
|
+
do {
|
|
131
|
+
let __result = try self.__implementation.loadFontFromURL(url: String(url))
|
|
132
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__shared_ptr_HybridFallbackFontSpec___ in
|
|
133
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__shared_ptr_HybridFallbackFontSpec___()
|
|
134
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_HybridFallbackFontSpec___(__promise)
|
|
135
|
+
__result
|
|
136
|
+
.then({ __result in __promiseHolder.resolve({ () -> bridge.std__shared_ptr_HybridFallbackFontSpec_ in
|
|
137
|
+
let __cxxWrapped = __result.getCxxWrapper()
|
|
138
|
+
return __cxxWrapped.getCxxPart()
|
|
139
|
+
}()) })
|
|
140
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
141
|
+
return __promise
|
|
142
|
+
}()
|
|
143
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__shared_ptr_HybridFallbackFontSpec____(__resultCpp)
|
|
144
|
+
} catch (let __error) {
|
|
145
|
+
let __exceptionPtr = __error.toCpp()
|
|
146
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__shared_ptr_HybridFallbackFontSpec____(__exceptionPtr)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@inline(__always)
|
|
151
|
+
public final func loadFontFromResource(resource: std.string) -> bridge.Result_std__shared_ptr_HybridFallbackFontSpec__ {
|
|
152
|
+
do {
|
|
153
|
+
let __result = try self.__implementation.loadFontFromResource(resource: String(resource))
|
|
154
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_HybridFallbackFontSpec_ in
|
|
155
|
+
let __cxxWrapped = __result.getCxxWrapper()
|
|
156
|
+
return __cxxWrapped.getCxxPart()
|
|
157
|
+
}()
|
|
158
|
+
return bridge.create_Result_std__shared_ptr_HybridFallbackFontSpec__(__resultCpp)
|
|
159
|
+
} catch (let __error) {
|
|
160
|
+
let __exceptionPtr = __error.toCpp()
|
|
161
|
+
return bridge.create_Result_std__shared_ptr_HybridFallbackFontSpec__(__exceptionPtr)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@inline(__always)
|
|
166
|
+
public final func loadFontFromBytes(bytes: ArrayBuffer) -> bridge.Result_std__shared_ptr_HybridFallbackFontSpec__ {
|
|
167
|
+
do {
|
|
168
|
+
let __result = try self.__implementation.loadFontFromBytes(bytes: bytes)
|
|
169
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_HybridFallbackFontSpec_ in
|
|
170
|
+
let __cxxWrapped = __result.getCxxWrapper()
|
|
171
|
+
return __cxxWrapped.getCxxPart()
|
|
172
|
+
}()
|
|
173
|
+
return bridge.create_Result_std__shared_ptr_HybridFallbackFontSpec__(__resultCpp)
|
|
174
|
+
} catch (let __error) {
|
|
175
|
+
let __exceptionPtr = __error.toCpp()
|
|
176
|
+
return bridge.create_Result_std__shared_ptr_HybridFallbackFontSpec__(__exceptionPtr)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
@inline(__always)
|
|
181
|
+
public final func loadFontByName(name: std.string) -> bridge.Result_std__shared_ptr_HybridFallbackFontSpec__ {
|
|
182
|
+
do {
|
|
183
|
+
let __result = try self.__implementation.loadFontByName(name: String(name))
|
|
184
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_HybridFallbackFontSpec_ in
|
|
185
|
+
let __cxxWrapped = __result.getCxxWrapper()
|
|
186
|
+
return __cxxWrapped.getCxxPart()
|
|
187
|
+
}()
|
|
188
|
+
return bridge.create_Result_std__shared_ptr_HybridFallbackFontSpec__(__resultCpp)
|
|
189
|
+
} catch (let __error) {
|
|
190
|
+
let __exceptionPtr = __error.toCpp()
|
|
191
|
+
return bridge.create_Result_std__shared_ptr_HybridFallbackFontSpec__(__exceptionPtr)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
@inline(__always)
|
|
196
|
+
public final func getSystemDefaultFont() -> bridge.Result_std__shared_ptr_HybridFallbackFontSpec__ {
|
|
197
|
+
do {
|
|
198
|
+
let __result = try self.__implementation.getSystemDefaultFont()
|
|
199
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_HybridFallbackFontSpec_ in
|
|
200
|
+
let __cxxWrapped = __result.getCxxWrapper()
|
|
201
|
+
return __cxxWrapped.getCxxPart()
|
|
202
|
+
}()
|
|
203
|
+
return bridge.create_Result_std__shared_ptr_HybridFallbackFontSpec__(__resultCpp)
|
|
204
|
+
} catch (let __error) {
|
|
205
|
+
let __exceptionPtr = __error.toCpp()
|
|
206
|
+
return bridge.create_Result_std__shared_ptr_HybridFallbackFontSpec__(__exceptionPtr)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@inline(__always)
|
|
211
|
+
public final func setFontsForWeight(weight: Double, fonts: bridge.std__vector_std__shared_ptr_HybridFallbackFontSpec__) -> bridge.Result_void_ {
|
|
212
|
+
do {
|
|
213
|
+
try self.__implementation.setFontsForWeight(weight: weight, fonts: fonts.map({ __item in { () -> any HybridFallbackFontSpec in
|
|
214
|
+
let __unsafePointer = bridge.get_std__shared_ptr_HybridFallbackFontSpec_(__item)
|
|
215
|
+
let __instance = HybridFallbackFontSpec_cxx.fromUnsafe(__unsafePointer)
|
|
216
|
+
return __instance.getHybridFallbackFontSpec()
|
|
217
|
+
}() }))
|
|
218
|
+
return bridge.create_Result_void_()
|
|
219
|
+
} catch (let __error) {
|
|
220
|
+
let __exceptionPtr = __error.toCpp()
|
|
221
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
@inline(__always)
|
|
226
|
+
public final func applyFallbackFonts() -> bridge.Result_std__shared_ptr_Promise_void___ {
|
|
227
|
+
do {
|
|
228
|
+
let __result = try self.__implementation.applyFallbackFonts()
|
|
229
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_void__ in
|
|
230
|
+
let __promise = bridge.create_std__shared_ptr_Promise_void__()
|
|
231
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(__promise)
|
|
232
|
+
__result
|
|
233
|
+
.then({ __result in __promiseHolder.resolve() })
|
|
234
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
235
|
+
return __promise
|
|
236
|
+
}()
|
|
237
|
+
return bridge.create_Result_std__shared_ptr_Promise_void___(__resultCpp)
|
|
238
|
+
} catch (let __error) {
|
|
239
|
+
let __exceptionPtr = __error.toCpp()
|
|
240
|
+
return bridge.create_Result_std__shared_ptr_Promise_void___(__exceptionPtr)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
@inline(__always)
|
|
245
|
+
public final func clearFallbackFonts() -> bridge.Result_std__shared_ptr_Promise_void___ {
|
|
246
|
+
do {
|
|
247
|
+
let __result = try self.__implementation.clearFallbackFonts()
|
|
248
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_void__ in
|
|
249
|
+
let __promise = bridge.create_std__shared_ptr_Promise_void__()
|
|
250
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(__promise)
|
|
251
|
+
__result
|
|
252
|
+
.then({ __result in __promiseHolder.resolve() })
|
|
253
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
254
|
+
return __promise
|
|
255
|
+
}()
|
|
256
|
+
return bridge.create_Result_std__shared_ptr_Promise_void___(__resultCpp)
|
|
257
|
+
} catch (let __error) {
|
|
258
|
+
let __exceptionPtr = __error.toCpp()
|
|
259
|
+
return bridge.create_Result_std__shared_ptr_Promise_void___(__exceptionPtr)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// HybridFallbackFontSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
|
-
#include "
|
|
8
|
+
#include "HybridFallbackFontSpec.hpp"
|
|
9
9
|
|
|
10
10
|
namespace margelo::nitro::rive {
|
|
11
11
|
|
|
12
|
-
void
|
|
12
|
+
void HybridFallbackFontSpec::loadHybridMethods() {
|
|
13
13
|
// load base methods/properties
|
|
14
14
|
HybridObject::loadHybridMethods();
|
|
15
15
|
// load custom methods/properties
|
|
16
16
|
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// HybridFallbackFontSpec.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © Marc Rousavy @ Margelo
|
|
@@ -22,25 +22,25 @@ namespace margelo::nitro::rive {
|
|
|
22
22
|
using namespace margelo::nitro;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* An abstract base class for `
|
|
26
|
-
* Inherit this class to create instances of `
|
|
25
|
+
* An abstract base class for `FallbackFont`
|
|
26
|
+
* Inherit this class to create instances of `HybridFallbackFontSpec` in C++.
|
|
27
27
|
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
28
28
|
* @example
|
|
29
29
|
* ```cpp
|
|
30
|
-
* class
|
|
30
|
+
* class HybridFallbackFont: public HybridFallbackFontSpec {
|
|
31
31
|
* public:
|
|
32
|
-
*
|
|
32
|
+
* HybridFallbackFont(...): HybridObject(TAG) { ... }
|
|
33
33
|
* // ...
|
|
34
34
|
* };
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
class
|
|
37
|
+
class HybridFallbackFontSpec: public virtual HybridObject {
|
|
38
38
|
public:
|
|
39
39
|
// Constructor
|
|
40
|
-
explicit
|
|
40
|
+
explicit HybridFallbackFontSpec(): HybridObject(TAG) { }
|
|
41
41
|
|
|
42
42
|
// Destructor
|
|
43
|
-
~
|
|
43
|
+
~HybridFallbackFontSpec() override = default;
|
|
44
44
|
|
|
45
45
|
public:
|
|
46
46
|
// Properties
|
|
@@ -48,7 +48,7 @@ namespace margelo::nitro::rive {
|
|
|
48
48
|
|
|
49
49
|
public:
|
|
50
50
|
// Methods
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
|
|
53
53
|
protected:
|
|
54
54
|
// Hybrid Setup
|
|
@@ -56,7 +56,7 @@ namespace margelo::nitro::rive {
|
|
|
56
56
|
|
|
57
57
|
protected:
|
|
58
58
|
// Tag for logging
|
|
59
|
-
static constexpr auto TAG = "
|
|
59
|
+
static constexpr auto TAG = "FallbackFont";
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
} // namespace margelo::nitro::rive
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridRiveFontConfigSpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridRiveFontConfigSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::rive {
|
|
11
|
+
|
|
12
|
+
void HybridRiveFontConfigSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("loadFontFromURL", &HybridRiveFontConfigSpec::loadFontFromURL);
|
|
18
|
+
prototype.registerHybridMethod("loadFontFromResource", &HybridRiveFontConfigSpec::loadFontFromResource);
|
|
19
|
+
prototype.registerHybridMethod("loadFontFromBytes", &HybridRiveFontConfigSpec::loadFontFromBytes);
|
|
20
|
+
prototype.registerHybridMethod("loadFontByName", &HybridRiveFontConfigSpec::loadFontByName);
|
|
21
|
+
prototype.registerHybridMethod("getSystemDefaultFont", &HybridRiveFontConfigSpec::getSystemDefaultFont);
|
|
22
|
+
prototype.registerHybridMethod("setFontsForWeight", &HybridRiveFontConfigSpec::setFontsForWeight);
|
|
23
|
+
prototype.registerHybridMethod("applyFallbackFonts", &HybridRiveFontConfigSpec::applyFallbackFonts);
|
|
24
|
+
prototype.registerHybridMethod("clearFallbackFonts", &HybridRiveFontConfigSpec::clearFallbackFonts);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
} // namespace margelo::nitro::rive
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridRiveFontConfigSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 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 `HybridFallbackFontSpec` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::rive { class HybridFallbackFontSpec; }
|
|
18
|
+
|
|
19
|
+
#include <memory>
|
|
20
|
+
#include "HybridFallbackFontSpec.hpp"
|
|
21
|
+
#include <NitroModules/Promise.hpp>
|
|
22
|
+
#include <string>
|
|
23
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
24
|
+
#include <vector>
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::rive {
|
|
27
|
+
|
|
28
|
+
using namespace margelo::nitro;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* An abstract base class for `RiveFontConfig`
|
|
32
|
+
* Inherit this class to create instances of `HybridRiveFontConfigSpec` in C++.
|
|
33
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
34
|
+
* @example
|
|
35
|
+
* ```cpp
|
|
36
|
+
* class HybridRiveFontConfig: public HybridRiveFontConfigSpec {
|
|
37
|
+
* public:
|
|
38
|
+
* HybridRiveFontConfig(...): HybridObject(TAG) { ... }
|
|
39
|
+
* // ...
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
class HybridRiveFontConfigSpec: public virtual HybridObject {
|
|
44
|
+
public:
|
|
45
|
+
// Constructor
|
|
46
|
+
explicit HybridRiveFontConfigSpec(): HybridObject(TAG) { }
|
|
47
|
+
|
|
48
|
+
// Destructor
|
|
49
|
+
~HybridRiveFontConfigSpec() override = default;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Properties
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
// Methods
|
|
57
|
+
virtual std::shared_ptr<Promise<std::shared_ptr<HybridFallbackFontSpec>>> loadFontFromURL(const std::string& url) = 0;
|
|
58
|
+
virtual std::shared_ptr<HybridFallbackFontSpec> loadFontFromResource(const std::string& resource) = 0;
|
|
59
|
+
virtual std::shared_ptr<HybridFallbackFontSpec> loadFontFromBytes(const std::shared_ptr<ArrayBuffer>& bytes) = 0;
|
|
60
|
+
virtual std::shared_ptr<HybridFallbackFontSpec> loadFontByName(const std::string& name) = 0;
|
|
61
|
+
virtual std::shared_ptr<HybridFallbackFontSpec> getSystemDefaultFont() = 0;
|
|
62
|
+
virtual void setFontsForWeight(double weight, const std::vector<std::shared_ptr<HybridFallbackFontSpec>>& fonts) = 0;
|
|
63
|
+
virtual std::shared_ptr<Promise<void>> applyFallbackFonts() = 0;
|
|
64
|
+
virtual std::shared_ptr<Promise<void>> clearFallbackFonts() = 0;
|
|
65
|
+
|
|
66
|
+
protected:
|
|
67
|
+
// Hybrid Setup
|
|
68
|
+
void loadHybridMethods() override;
|
|
69
|
+
|
|
70
|
+
protected:
|
|
71
|
+
// Tag for logging
|
|
72
|
+
static constexpr auto TAG = "RiveFontConfig";
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
} // namespace margelo::nitro::rive
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rive-app/react-native",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Rive React Native",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"react": "19.0.0",
|
|
98
98
|
"react-native": "0.79.2",
|
|
99
99
|
"react-native-builder-bob": "^0.40.10",
|
|
100
|
-
"react-native-nitro-modules": "0.
|
|
100
|
+
"react-native-nitro-modules": "0.34.1",
|
|
101
101
|
"react-test-renderer": "19.0.0",
|
|
102
102
|
"release-it": "^17.10.0",
|
|
103
103
|
"turbo": "^1.10.7",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"peerDependencies": {
|
|
107
107
|
"react": "*",
|
|
108
108
|
"react-native": "*",
|
|
109
|
-
"react-native-nitro-modules": ">=0.33.2"
|
|
109
|
+
"react-native-nitro-modules": ">=0.33.2 <0.35.0"
|
|
110
110
|
},
|
|
111
111
|
"workspaces": [
|
|
112
112
|
"example",
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import { Image } from 'react-native';
|
|
3
|
+
import type {
|
|
4
|
+
RiveFontConfig,
|
|
5
|
+
FallbackFont,
|
|
6
|
+
} from '../specs/RiveFontConfig.nitro';
|
|
7
|
+
|
|
8
|
+
const RiveFontConfigInternal =
|
|
9
|
+
NitroModules.createHybridObject<RiveFontConfig>('RiveFontConfig');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A font source that can be:
|
|
13
|
+
* - `number` — a Metro `require('./Font.ttf')` asset ID
|
|
14
|
+
* - `{ uri: string }` — a URI object (http/https URL, file:// path, or resource name)
|
|
15
|
+
* - `string` — a native resource name (e.g. "kanit_regular.ttf") or URL
|
|
16
|
+
* - `{ name: string }` — a system font name (e.g. "Arial", "sans-serif")
|
|
17
|
+
* - `ArrayBuffer` — raw font bytes (TTF/OTF)
|
|
18
|
+
*/
|
|
19
|
+
export type FontSource =
|
|
20
|
+
| number
|
|
21
|
+
| { uri: string }
|
|
22
|
+
| { name: string }
|
|
23
|
+
| string
|
|
24
|
+
| ArrayBuffer;
|
|
25
|
+
|
|
26
|
+
export type FontWeight = number | 'default';
|
|
27
|
+
|
|
28
|
+
export type FallbackFontMap = Partial<Record<FontWeight, FallbackFont[]>>;
|
|
29
|
+
|
|
30
|
+
const DEFAULT_WEIGHT = 0;
|
|
31
|
+
|
|
32
|
+
function resolveWeight(key: string): number {
|
|
33
|
+
return key === 'default' ? DEFAULT_WEIGHT : Number(key);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export namespace RiveFonts {
|
|
37
|
+
export async function loadFont(source: FontSource): Promise<FallbackFont> {
|
|
38
|
+
if (source instanceof ArrayBuffer) {
|
|
39
|
+
return RiveFontConfigInternal.loadFontFromBytes(source);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (typeof source === 'number') {
|
|
43
|
+
const resolved = Image.resolveAssetSource(source);
|
|
44
|
+
if (!resolved?.uri) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Invalid font asset: could not resolve require() ID ${source}. Ensure 'ttf' is in metro.config.js assetExts.`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return loadFontByURI(resolved.uri);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (typeof source === 'object' && 'name' in source) {
|
|
53
|
+
return RiveFontConfigInternal.loadFontByName(source.name);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (typeof source === 'object' && 'uri' in source) {
|
|
57
|
+
return loadFontByURI(source.uri);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (typeof source === 'string') {
|
|
61
|
+
if (/^https?:\/\//.test(source) || /^file:\/\//.test(source)) {
|
|
62
|
+
return RiveFontConfigInternal.loadFontFromURL(source);
|
|
63
|
+
}
|
|
64
|
+
return RiveFontConfigInternal.loadFontFromResource(source);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
throw new Error(`Invalid font source: ${String(source)}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function systemFallback(): FallbackFont {
|
|
71
|
+
return RiveFontConfigInternal.getSystemDefaultFont();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function setFallbackFonts(
|
|
75
|
+
fontsByWeight: FallbackFontMap
|
|
76
|
+
): Promise<void> {
|
|
77
|
+
for (const [key, fonts] of Object.entries(fontsByWeight)) {
|
|
78
|
+
if (fonts) {
|
|
79
|
+
RiveFontConfigInternal.setFontsForWeight(resolveWeight(key), fonts);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
await RiveFontConfigInternal.applyFallbackFonts();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function clearFallbackFonts(): Promise<void> {
|
|
86
|
+
return RiveFontConfigInternal.clearFallbackFonts();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function loadFontByURI(uri: string): Promise<FallbackFont> | FallbackFont {
|
|
91
|
+
if (/^https?:\/\//.test(uri) || /^file:\/\//.test(uri)) {
|
|
92
|
+
return RiveFontConfigInternal.loadFontFromURL(uri);
|
|
93
|
+
}
|
|
94
|
+
return RiveFontConfigInternal.loadFontFromResource(uri);
|
|
95
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -39,6 +39,13 @@ export { Alignment } from './core/Alignment';
|
|
|
39
39
|
export { RiveFileFactory } from './core/RiveFile';
|
|
40
40
|
export { RiveImages } from './core/RiveImages';
|
|
41
41
|
export type { RiveImage } from './specs/RiveImage.nitro';
|
|
42
|
+
export {
|
|
43
|
+
RiveFonts,
|
|
44
|
+
type FontSource,
|
|
45
|
+
type FontWeight,
|
|
46
|
+
type FallbackFontMap,
|
|
47
|
+
} from './core/RiveFonts';
|
|
48
|
+
export type { FallbackFont } from './specs/RiveFontConfig.nitro';
|
|
42
49
|
export { RiveColor } from './core/RiveColor';
|
|
43
50
|
export { type RiveEvent, RiveEventType } from './core/Events';
|
|
44
51
|
export { type RiveError, RiveErrorType } from './core/Errors';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
|
|
3
|
+
export interface FallbackFont
|
|
4
|
+
extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {}
|
|
5
|
+
|
|
6
|
+
export interface RiveFontConfig
|
|
7
|
+
extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
|
|
8
|
+
loadFontFromURL(url: string): Promise<FallbackFont>;
|
|
9
|
+
loadFontFromResource(resource: string): FallbackFont;
|
|
10
|
+
loadFontFromBytes(bytes: ArrayBuffer): FallbackFont;
|
|
11
|
+
loadFontByName(name: string): FallbackFont;
|
|
12
|
+
getSystemDefaultFont(): FallbackFont;
|
|
13
|
+
setFontsForWeight(weight: number, fonts: FallbackFont[]): void;
|
|
14
|
+
applyFallbackFonts(): Promise<void>;
|
|
15
|
+
clearFallbackFonts(): Promise<void>;
|
|
16
|
+
}
|
package/ios/Rive.swift
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Rive.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/Rive.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,WAAW,IACf,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC;IACzD,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACxC"}
|