@rive-app/react-native 0.1.1 → 0.1.2

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.
Files changed (61) hide show
  1. package/README.md +18 -7
  2. package/android/src/main/java/com/margelo/nitro/rive/HybridRiveFile.kt +0 -1
  3. package/android/src/main/java/com/margelo/nitro/rive/HybridViewModelInstance.kt +26 -47
  4. package/android/src/main/java/com/margelo/nitro/rive/HybridViewModelListProperty.kt +64 -0
  5. package/ios/BaseHybridViewModelProperty.swift +9 -0
  6. package/ios/HybridViewModelInstance.swift +5 -0
  7. package/ios/HybridViewModelListProperty.swift +62 -0
  8. package/lib/module/hooks/useRiveColor.js +0 -1
  9. package/lib/module/hooks/useRiveColor.js.map +1 -1
  10. package/lib/module/hooks/useRiveList.js +71 -0
  11. package/lib/module/hooks/useRiveList.js.map +1 -0
  12. package/lib/module/hooks/useRiveProperty.js +6 -12
  13. package/lib/module/hooks/useRiveProperty.js.map +1 -1
  14. package/lib/module/hooks/useViewModelInstance.js +139 -0
  15. package/lib/module/hooks/useViewModelInstance.js.map +1 -0
  16. package/lib/module/index.js +2 -0
  17. package/lib/module/index.js.map +1 -1
  18. package/lib/typescript/src/hooks/useRiveColor.d.ts +6 -4
  19. package/lib/typescript/src/hooks/useRiveColor.d.ts.map +1 -1
  20. package/lib/typescript/src/hooks/useRiveList.d.ts +11 -0
  21. package/lib/typescript/src/hooks/useRiveList.d.ts.map +1 -0
  22. package/lib/typescript/src/hooks/useRiveProperty.d.ts +6 -1
  23. package/lib/typescript/src/hooks/useRiveProperty.d.ts.map +1 -1
  24. package/lib/typescript/src/hooks/useViewModelInstance.d.ts +86 -0
  25. package/lib/typescript/src/hooks/useViewModelInstance.d.ts.map +1 -0
  26. package/lib/typescript/src/index.d.ts +4 -1
  27. package/lib/typescript/src/index.d.ts.map +1 -1
  28. package/lib/typescript/src/specs/ViewModel.nitro.d.ts +24 -0
  29. package/lib/typescript/src/specs/ViewModel.nitro.d.ts.map +1 -1
  30. package/lib/typescript/src/types.d.ts +47 -3
  31. package/lib/typescript/src/types.d.ts.map +1 -1
  32. package/nitrogen/generated/android/c++/JHybridViewModelInstanceSpec.cpp +9 -0
  33. package/nitrogen/generated/android/c++/JHybridViewModelInstanceSpec.hpp +1 -0
  34. package/nitrogen/generated/android/c++/JHybridViewModelListPropertySpec.cpp +102 -0
  35. package/nitrogen/generated/android/c++/JHybridViewModelListPropertySpec.hpp +73 -0
  36. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/HybridViewModelInstanceSpec.kt +4 -0
  37. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/HybridViewModelListPropertySpec.kt +92 -0
  38. package/nitrogen/generated/android/rive+autolinking.cmake +2 -0
  39. package/nitrogen/generated/android/riveOnLoad.cpp +2 -0
  40. package/nitrogen/generated/ios/RNRive-Swift-Cxx-Bridge.cpp +17 -0
  41. package/nitrogen/generated/ios/RNRive-Swift-Cxx-Bridge.hpp +44 -0
  42. package/nitrogen/generated/ios/RNRive-Swift-Cxx-Umbrella.hpp +5 -0
  43. package/nitrogen/generated/ios/c++/HybridViewModelInstanceSpecSwift.hpp +11 -0
  44. package/nitrogen/generated/ios/c++/HybridViewModelListPropertySpecSwift.cpp +11 -0
  45. package/nitrogen/generated/ios/c++/HybridViewModelListPropertySpecSwift.hpp +134 -0
  46. package/nitrogen/generated/ios/swift/HybridViewModelInstanceSpec.swift +1 -0
  47. package/nitrogen/generated/ios/swift/HybridViewModelInstanceSpec_cxx.swift +21 -0
  48. package/nitrogen/generated/ios/swift/HybridViewModelListPropertySpec.swift +63 -0
  49. package/nitrogen/generated/ios/swift/HybridViewModelListPropertySpec_cxx.swift +248 -0
  50. package/nitrogen/generated/shared/c++/HybridViewModelInstanceSpec.cpp +1 -0
  51. package/nitrogen/generated/shared/c++/HybridViewModelInstanceSpec.hpp +4 -0
  52. package/nitrogen/generated/shared/c++/HybridViewModelListPropertySpec.cpp +30 -0
  53. package/nitrogen/generated/shared/c++/HybridViewModelListPropertySpec.hpp +76 -0
  54. package/package.json +3 -3
  55. package/src/hooks/useRiveColor.ts +7 -4
  56. package/src/hooks/useRiveList.ts +108 -0
  57. package/src/hooks/useRiveProperty.ts +19 -12
  58. package/src/hooks/useViewModelInstance.ts +195 -0
  59. package/src/index.tsx +4 -0
  60. package/src/specs/ViewModel.nitro.ts +28 -0
  61. package/src/types.tsx +58 -3
@@ -0,0 +1,248 @@
1
+ ///
2
+ /// HybridViewModelListPropertySpec_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
+
11
+ /**
12
+ * A class implementation that bridges HybridViewModelListPropertySpec 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 HybridViewModelListPropertySpec_cxx : HybridViewModelPropertySpec_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 `HybridViewModelListPropertySpec` Swift protocol.
30
+ */
31
+ private var __implementation: any HybridViewModelListPropertySpec
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_HybridViewModelListPropertySpec_
37
+
38
+ /**
39
+ * Create a new `HybridViewModelListPropertySpec_cxx` that wraps the given `HybridViewModelListPropertySpec`.
40
+ * All properties and methods bridge to C++ types.
41
+ */
42
+ public init(_ implementation: any HybridViewModelListPropertySpec) {
43
+ self.__implementation = implementation
44
+ self.__cxxPart = .init()
45
+ super.init(implementation)
46
+ }
47
+
48
+ /**
49
+ * Get the actual `HybridViewModelListPropertySpec` instance this class wraps.
50
+ */
51
+ @inline(__always)
52
+ public func getHybridViewModelListPropertySpec() -> any HybridViewModelListPropertySpec {
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 override func toUnsafe() -> UnsafeMutableRawPointer {
61
+ return Unmanaged.passRetained(self).toOpaque()
62
+ }
63
+
64
+ /**
65
+ * Casts an unsafe pointer to a `HybridViewModelListPropertySpec_cxx`.
66
+ * The pointer has to be a retained opaque `Unmanaged<HybridViewModelListPropertySpec_cxx>`.
67
+ * This removes one strong reference from the object!
68
+ */
69
+ public override class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridViewModelListPropertySpec_cxx {
70
+ return Unmanaged<HybridViewModelListPropertySpec_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<HybridViewModelListPropertySpec>`.
76
+ */
77
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridViewModelListPropertySpec_ {
78
+ let cachedCxxPart = self.__cxxPart.lock()
79
+ if Bool(fromCxx: cachedCxxPart) {
80
+ return cachedCxxPart
81
+ } else {
82
+ let newCxxPart = bridge.create_std__shared_ptr_HybridViewModelListPropertySpec_(self.toUnsafe())
83
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridViewModelListPropertySpec_(newCxxPart)
84
+ return newCxxPart
85
+ }
86
+ }
87
+
88
+ public override func getCxxPart() -> bridge.std__shared_ptr_HybridViewModelPropertySpec_ {
89
+ let ownCxxPart: bridge.std__shared_ptr_HybridViewModelListPropertySpec_ = getCxxPart()
90
+ return bridge.upcast_ViewModelListProperty_to_ViewModelProperty(ownCxxPart)
91
+ }
92
+
93
+ /**
94
+ * Get the memory size of the Swift class (plus size of any other allocations)
95
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
96
+ */
97
+ @inline(__always)
98
+ public override var memorySize: Int {
99
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
100
+ }
101
+
102
+ /**
103
+ * Call dispose() on the Swift class.
104
+ * This _may_ be called manually from JS.
105
+ */
106
+ @inline(__always)
107
+ public override func dispose() {
108
+ self.__implementation.dispose()
109
+ }
110
+
111
+ /**
112
+ * Call toString() on the Swift class.
113
+ */
114
+ @inline(__always)
115
+ public override func toString() -> String {
116
+ return self.__implementation.toString()
117
+ }
118
+
119
+ // Properties
120
+ public final var length: Double {
121
+ @inline(__always)
122
+ get {
123
+ return self.__implementation.length
124
+ }
125
+ }
126
+
127
+ // Methods
128
+ @inline(__always)
129
+ public final func getInstanceAt(index: Double) -> bridge.Result_std__optional_std__shared_ptr_HybridViewModelInstanceSpec___ {
130
+ do {
131
+ let __result = try self.__implementation.getInstanceAt(index: index)
132
+ let __resultCpp = { () -> bridge.std__optional_std__shared_ptr_HybridViewModelInstanceSpec__ in
133
+ if let __unwrappedValue = __result {
134
+ return bridge.create_std__optional_std__shared_ptr_HybridViewModelInstanceSpec__({ () -> bridge.std__shared_ptr_HybridViewModelInstanceSpec_ in
135
+ let __cxxWrapped = __unwrappedValue.getCxxWrapper()
136
+ return __cxxWrapped.getCxxPart()
137
+ }())
138
+ } else {
139
+ return .init()
140
+ }
141
+ }()
142
+ return bridge.create_Result_std__optional_std__shared_ptr_HybridViewModelInstanceSpec___(__resultCpp)
143
+ } catch (let __error) {
144
+ let __exceptionPtr = __error.toCpp()
145
+ return bridge.create_Result_std__optional_std__shared_ptr_HybridViewModelInstanceSpec___(__exceptionPtr)
146
+ }
147
+ }
148
+
149
+ @inline(__always)
150
+ public final func addInstance(instance: bridge.std__shared_ptr_HybridViewModelInstanceSpec_) -> bridge.Result_void_ {
151
+ do {
152
+ try self.__implementation.addInstance(instance: { () -> HybridViewModelInstanceSpec in
153
+ let __unsafePointer = bridge.get_std__shared_ptr_HybridViewModelInstanceSpec_(instance)
154
+ let __instance = HybridViewModelInstanceSpec_cxx.fromUnsafe(__unsafePointer)
155
+ return __instance.getHybridViewModelInstanceSpec()
156
+ }())
157
+ return bridge.create_Result_void_()
158
+ } catch (let __error) {
159
+ let __exceptionPtr = __error.toCpp()
160
+ return bridge.create_Result_void_(__exceptionPtr)
161
+ }
162
+ }
163
+
164
+ @inline(__always)
165
+ public final func addInstanceAt(instance: bridge.std__shared_ptr_HybridViewModelInstanceSpec_, index: Double) -> bridge.Result_bool_ {
166
+ do {
167
+ let __result = try self.__implementation.addInstanceAt(instance: { () -> HybridViewModelInstanceSpec in
168
+ let __unsafePointer = bridge.get_std__shared_ptr_HybridViewModelInstanceSpec_(instance)
169
+ let __instance = HybridViewModelInstanceSpec_cxx.fromUnsafe(__unsafePointer)
170
+ return __instance.getHybridViewModelInstanceSpec()
171
+ }(), index: index)
172
+ let __resultCpp = __result
173
+ return bridge.create_Result_bool_(__resultCpp)
174
+ } catch (let __error) {
175
+ let __exceptionPtr = __error.toCpp()
176
+ return bridge.create_Result_bool_(__exceptionPtr)
177
+ }
178
+ }
179
+
180
+ @inline(__always)
181
+ public final func removeInstance(instance: bridge.std__shared_ptr_HybridViewModelInstanceSpec_) -> bridge.Result_void_ {
182
+ do {
183
+ try self.__implementation.removeInstance(instance: { () -> HybridViewModelInstanceSpec in
184
+ let __unsafePointer = bridge.get_std__shared_ptr_HybridViewModelInstanceSpec_(instance)
185
+ let __instance = HybridViewModelInstanceSpec_cxx.fromUnsafe(__unsafePointer)
186
+ return __instance.getHybridViewModelInstanceSpec()
187
+ }())
188
+ return bridge.create_Result_void_()
189
+ } catch (let __error) {
190
+ let __exceptionPtr = __error.toCpp()
191
+ return bridge.create_Result_void_(__exceptionPtr)
192
+ }
193
+ }
194
+
195
+ @inline(__always)
196
+ public final func removeInstanceAt(index: Double) -> bridge.Result_void_ {
197
+ do {
198
+ try self.__implementation.removeInstanceAt(index: index)
199
+ return bridge.create_Result_void_()
200
+ } catch (let __error) {
201
+ let __exceptionPtr = __error.toCpp()
202
+ return bridge.create_Result_void_(__exceptionPtr)
203
+ }
204
+ }
205
+
206
+ @inline(__always)
207
+ public final func swap(index1: Double, index2: Double) -> bridge.Result_bool_ {
208
+ do {
209
+ let __result = try self.__implementation.swap(index1: index1, index2: index2)
210
+ let __resultCpp = __result
211
+ return bridge.create_Result_bool_(__resultCpp)
212
+ } catch (let __error) {
213
+ let __exceptionPtr = __error.toCpp()
214
+ return bridge.create_Result_bool_(__exceptionPtr)
215
+ }
216
+ }
217
+
218
+ @inline(__always)
219
+ public final func addListener(onChanged: bridge.Func_void) -> bridge.Result_std__function_void____ {
220
+ do {
221
+ let __result = try self.__implementation.addListener(onChanged: { () -> () -> Void in
222
+ let __wrappedFunction = bridge.wrap_Func_void(onChanged)
223
+ return { () -> Void in
224
+ __wrappedFunction.call()
225
+ }
226
+ }())
227
+ let __resultCpp = { () -> bridge.Func_void in
228
+ let __closureWrapper = Func_void(__result)
229
+ return bridge.create_Func_void(__closureWrapper.toUnsafe())
230
+ }()
231
+ return bridge.create_Result_std__function_void____(__resultCpp)
232
+ } catch (let __error) {
233
+ let __exceptionPtr = __error.toCpp()
234
+ return bridge.create_Result_std__function_void____(__exceptionPtr)
235
+ }
236
+ }
237
+
238
+ @inline(__always)
239
+ public final func removeListeners() -> bridge.Result_void_ {
240
+ do {
241
+ try self.__implementation.removeListeners()
242
+ return bridge.create_Result_void_()
243
+ } catch (let __error) {
244
+ let __exceptionPtr = __error.toCpp()
245
+ return bridge.create_Result_void_(__exceptionPtr)
246
+ }
247
+ }
248
+ }
@@ -22,6 +22,7 @@ namespace margelo::nitro::rive {
22
22
  prototype.registerHybridMethod("enumProperty", &HybridViewModelInstanceSpec::enumProperty);
23
23
  prototype.registerHybridMethod("triggerProperty", &HybridViewModelInstanceSpec::triggerProperty);
24
24
  prototype.registerHybridMethod("imageProperty", &HybridViewModelInstanceSpec::imageProperty);
25
+ prototype.registerHybridMethod("listProperty", &HybridViewModelInstanceSpec::listProperty);
25
26
  });
26
27
  }
27
28
 
@@ -27,6 +27,8 @@ namespace margelo::nitro::rive { class HybridViewModelEnumPropertySpec; }
27
27
  namespace margelo::nitro::rive { class HybridViewModelTriggerPropertySpec; }
28
28
  // Forward declaration of `HybridViewModelImagePropertySpec` to properly resolve imports.
29
29
  namespace margelo::nitro::rive { class HybridViewModelImagePropertySpec; }
30
+ // Forward declaration of `HybridViewModelListPropertySpec` to properly resolve imports.
31
+ namespace margelo::nitro::rive { class HybridViewModelListPropertySpec; }
30
32
 
31
33
  #include <string>
32
34
  #include <memory>
@@ -38,6 +40,7 @@ namespace margelo::nitro::rive { class HybridViewModelImagePropertySpec; }
38
40
  #include "HybridViewModelEnumPropertySpec.hpp"
39
41
  #include "HybridViewModelTriggerPropertySpec.hpp"
40
42
  #include "HybridViewModelImagePropertySpec.hpp"
43
+ #include "HybridViewModelListPropertySpec.hpp"
41
44
 
42
45
  namespace margelo::nitro::rive {
43
46
 
@@ -77,6 +80,7 @@ namespace margelo::nitro::rive {
77
80
  virtual std::optional<std::shared_ptr<HybridViewModelEnumPropertySpec>> enumProperty(const std::string& path) = 0;
78
81
  virtual std::optional<std::shared_ptr<HybridViewModelTriggerPropertySpec>> triggerProperty(const std::string& path) = 0;
79
82
  virtual std::optional<std::shared_ptr<HybridViewModelImagePropertySpec>> imageProperty(const std::string& path) = 0;
83
+ virtual std::optional<std::shared_ptr<HybridViewModelListPropertySpec>> listProperty(const std::string& path) = 0;
80
84
 
81
85
  protected:
82
86
  // Hybrid Setup
@@ -0,0 +1,30 @@
1
+ ///
2
+ /// HybridViewModelListPropertySpec.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 "HybridViewModelListPropertySpec.hpp"
9
+
10
+ namespace margelo::nitro::rive {
11
+
12
+ void HybridViewModelListPropertySpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ HybridViewModelPropertySpec::loadHybridMethods();
16
+ // load custom methods/properties
17
+ registerHybrids(this, [](Prototype& prototype) {
18
+ prototype.registerHybridGetter("length", &HybridViewModelListPropertySpec::getLength);
19
+ prototype.registerHybridMethod("getInstanceAt", &HybridViewModelListPropertySpec::getInstanceAt);
20
+ prototype.registerHybridMethod("addInstance", &HybridViewModelListPropertySpec::addInstance);
21
+ prototype.registerHybridMethod("addInstanceAt", &HybridViewModelListPropertySpec::addInstanceAt);
22
+ prototype.registerHybridMethod("removeInstance", &HybridViewModelListPropertySpec::removeInstance);
23
+ prototype.registerHybridMethod("removeInstanceAt", &HybridViewModelListPropertySpec::removeInstanceAt);
24
+ prototype.registerHybridMethod("swap", &HybridViewModelListPropertySpec::swap);
25
+ prototype.registerHybridMethod("addListener", &HybridViewModelListPropertySpec::addListener);
26
+ prototype.registerHybridMethod("removeListeners", &HybridViewModelListPropertySpec::removeListeners);
27
+ });
28
+ }
29
+
30
+ } // namespace margelo::nitro::rive
@@ -0,0 +1,76 @@
1
+ ///
2
+ /// HybridViewModelListPropertySpec.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 `HybridViewModelInstanceSpec` to properly resolve imports.
17
+ namespace margelo::nitro::rive { class HybridViewModelInstanceSpec; }
18
+ // Forward declaration of `HybridViewModelPropertySpec` to properly resolve imports.
19
+ namespace margelo::nitro::rive { class HybridViewModelPropertySpec; }
20
+
21
+ #include <memory>
22
+ #include "HybridViewModelInstanceSpec.hpp"
23
+ #include <optional>
24
+ #include <functional>
25
+ #include "HybridViewModelPropertySpec.hpp"
26
+
27
+ namespace margelo::nitro::rive {
28
+
29
+ using namespace margelo::nitro;
30
+
31
+ /**
32
+ * An abstract base class for `ViewModelListProperty`
33
+ * Inherit this class to create instances of `HybridViewModelListPropertySpec` in C++.
34
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
35
+ * @example
36
+ * ```cpp
37
+ * class HybridViewModelListProperty: public HybridViewModelListPropertySpec {
38
+ * public:
39
+ * HybridViewModelListProperty(...): HybridObject(TAG) { ... }
40
+ * // ...
41
+ * };
42
+ * ```
43
+ */
44
+ class HybridViewModelListPropertySpec: public virtual HybridObject, public virtual HybridViewModelPropertySpec {
45
+ public:
46
+ // Constructor
47
+ explicit HybridViewModelListPropertySpec(): HybridObject(TAG) { }
48
+
49
+ // Destructor
50
+ ~HybridViewModelListPropertySpec() override = default;
51
+
52
+ public:
53
+ // Properties
54
+ virtual double getLength() = 0;
55
+
56
+ public:
57
+ // Methods
58
+ virtual std::optional<std::shared_ptr<HybridViewModelInstanceSpec>> getInstanceAt(double index) = 0;
59
+ virtual void addInstance(const std::shared_ptr<HybridViewModelInstanceSpec>& instance) = 0;
60
+ virtual bool addInstanceAt(const std::shared_ptr<HybridViewModelInstanceSpec>& instance, double index) = 0;
61
+ virtual void removeInstance(const std::shared_ptr<HybridViewModelInstanceSpec>& instance) = 0;
62
+ virtual void removeInstanceAt(double index) = 0;
63
+ virtual bool swap(double index1, double index2) = 0;
64
+ virtual std::function<void()> addListener(const std::function<void()>& onChanged) = 0;
65
+ virtual void removeListeners() = 0;
66
+
67
+ protected:
68
+ // Hybrid Setup
69
+ void loadHybridMethods() override;
70
+
71
+ protected:
72
+ // Tag for logging
73
+ static constexpr auto TAG = "ViewModelListProperty";
74
+ };
75
+
76
+ } // namespace margelo::nitro::rive
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rive-app/react-native",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Rive React Native",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -64,8 +64,8 @@
64
64
  },
65
65
  "homepage": "https://github.com/rive-app/rive-nitro-react-native#readme",
66
66
  "runtimeVersions": {
67
- "ios": "6.12.0",
68
- "android": "10.5.0"
67
+ "ios": "6.12.3",
68
+ "android": "10.5.3"
69
69
  },
70
70
  "publishConfig": {
71
71
  "registry": "https://registry.npmjs.org/"
@@ -3,7 +3,6 @@ import type {
3
3
  ViewModelColorProperty,
4
4
  ViewModelInstance,
5
5
  } from '../specs/ViewModel.nitro';
6
- import { type UseRivePropertyResult } from '../types';
7
6
  import { useRiveProperty } from './useRiveProperty';
8
7
  import { RiveColor } from '../core/RiveColor';
9
8
 
@@ -11,6 +10,12 @@ const COLOR_PROPERTY_OPTIONS = {
11
10
  getProperty: (vmi: ViewModelInstance, p: string) => vmi.colorProperty(p),
12
11
  };
13
12
 
13
+ export interface UseRiveColorResult {
14
+ value: RiveColor | undefined;
15
+ setValue: (value: RiveColor | string) => void;
16
+ error: Error | null;
17
+ }
18
+
14
19
  /**
15
20
  * Hook for interacting with color ViewModel instance properties.
16
21
  *
@@ -21,9 +26,7 @@ const COLOR_PROPERTY_OPTIONS = {
21
26
  export function useRiveColor(
22
27
  path: string,
23
28
  viewModelInstance?: ViewModelInstance | null
24
- ): UseRivePropertyResult<RiveColor> & {
25
- setValue: (value: RiveColor | string) => void;
26
- } {
29
+ ): UseRiveColorResult {
27
30
  const [rawValue, setRawValue, error] = useRiveProperty<
28
31
  ViewModelColorProperty,
29
32
  number
@@ -0,0 +1,108 @@
1
+ import { useCallback, useEffect, useState, useMemo } from 'react';
2
+ import type { ViewModelInstance } from '../specs/ViewModel.nitro';
3
+ import type { UseRiveListResult } from '../types';
4
+
5
+ /**
6
+ * Hook for interacting with list ViewModel instance properties.
7
+ *
8
+ * @param path - The path to the list property
9
+ * @param viewModelInstance - The ViewModelInstance containing the list property
10
+ * @returns An object with list length, manipulation methods, and error state
11
+ */
12
+ export function useRiveList(
13
+ path: string,
14
+ viewModelInstance?: ViewModelInstance | null
15
+ ): UseRiveListResult {
16
+ const [error, setError] = useState<Error | null>(null);
17
+ const [revision, setRevision] = useState(0);
18
+
19
+ useEffect(() => {
20
+ setError(null);
21
+ }, [path, viewModelInstance]);
22
+
23
+ const property = useMemo(() => {
24
+ if (!viewModelInstance) return undefined;
25
+ return viewModelInstance.listProperty(path);
26
+ }, [viewModelInstance, path]);
27
+
28
+ useEffect(() => {
29
+ if (viewModelInstance && !property) {
30
+ setError(
31
+ new Error(`List property "${path}" not found in the ViewModel instance`)
32
+ );
33
+ }
34
+ }, [viewModelInstance, property, path]);
35
+
36
+ useEffect(() => {
37
+ if (!property) return;
38
+
39
+ const removeListener = property.addListener(() => {
40
+ setRevision((r) => r + 1);
41
+ });
42
+
43
+ return () => {
44
+ removeListener();
45
+ property.removeListeners();
46
+ property.dispose();
47
+ };
48
+ }, [property]);
49
+
50
+ const length = useMemo(() => {
51
+ // revision is used to trigger re-computation when list changes
52
+ revision;
53
+ return property?.length ?? 0;
54
+ }, [property, revision]);
55
+
56
+ const getInstanceAt = useCallback(
57
+ (index: number) => {
58
+ return property?.getInstanceAt(index);
59
+ },
60
+ [property]
61
+ );
62
+
63
+ const addInstance = useCallback(
64
+ (instance: ViewModelInstance) => {
65
+ property?.addInstance(instance);
66
+ },
67
+ [property]
68
+ );
69
+
70
+ const addInstanceAt = useCallback(
71
+ (instance: ViewModelInstance, index: number) => {
72
+ return property?.addInstanceAt(instance, index) ?? false;
73
+ },
74
+ [property]
75
+ );
76
+
77
+ const removeInstance = useCallback(
78
+ (instance: ViewModelInstance) => {
79
+ property?.removeInstance(instance);
80
+ },
81
+ [property]
82
+ );
83
+
84
+ const removeInstanceAt = useCallback(
85
+ (index: number) => {
86
+ property?.removeInstanceAt(index);
87
+ },
88
+ [property]
89
+ );
90
+
91
+ const swap = useCallback(
92
+ (index1: number, index2: number) => {
93
+ return property?.swap(index1, index2) ?? false;
94
+ },
95
+ [property]
96
+ );
97
+
98
+ return {
99
+ length,
100
+ getInstanceAt,
101
+ addInstance,
102
+ addInstanceAt,
103
+ removeInstance,
104
+ removeInstanceAt,
105
+ swap,
106
+ error,
107
+ };
108
+ }
@@ -28,7 +28,12 @@ export function useRiveProperty<P extends ViewModelProperty, T>(
28
28
  /** Optional override callback for property events (mainly used by triggers) */
29
29
  onPropertyEventOverride?: (...args: any[]) => void;
30
30
  }
31
- ): [T | undefined, (value: T) => void, Error | null, P | undefined] {
31
+ ): [
32
+ T | undefined,
33
+ (value: T | ((prevValue: T | undefined) => T)) => void,
34
+ Error | null,
35
+ P | undefined,
36
+ ] {
32
37
  const [value, setValue] = useState<T | undefined>(undefined);
33
38
  const [error, setError] = useState<Error | null>(null);
34
39
 
@@ -61,25 +66,21 @@ export function useRiveProperty<P extends ViewModelProperty, T>(
61
66
 
62
67
  // If an override callback is provided, use it.
63
68
  // Otherwise, use the default callback.
64
- if (options.onPropertyEventOverride) {
65
- property.addListener(options.onPropertyEventOverride);
66
- } else {
67
- property.addListener((newValue) => {
68
- setValue(newValue);
69
- });
70
- }
69
+ const removeListener = options.onPropertyEventOverride
70
+ ? property.addListener(options.onPropertyEventOverride)
71
+ : property.addListener((newValue) => {
72
+ setValue(newValue);
73
+ });
71
74
 
72
- // Cleanup: Remove listeners and dispose of the property
73
- // This ensures proper cleanup of event listeners and resources
74
75
  return () => {
75
- property.removeListeners();
76
+ removeListener();
76
77
  property.dispose();
77
78
  };
78
79
  }, [options, property]);
79
80
 
80
81
  // Set the value of the property
81
82
  const setPropertyValue = useCallback(
82
- (newValue: T) => {
83
+ (valueOrUpdater: T | ((prevValue: T | undefined) => T)) => {
83
84
  if (!property) {
84
85
  setError(
85
86
  new Error(
@@ -87,6 +88,12 @@ export function useRiveProperty<P extends ViewModelProperty, T>(
87
88
  )
88
89
  );
89
90
  } else {
91
+ const newValue =
92
+ typeof valueOrUpdater === 'function'
93
+ ? (valueOrUpdater as (prevValue: T | undefined) => T)(
94
+ property.value
95
+ )
96
+ : valueOrUpdater;
90
97
  property.value = newValue;
91
98
  }
92
99
  },