@rive-app/react-native 0.1.1-beta.1 → 0.1.1
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/BaseHybridViewModelProperty.kt +9 -7
- package/android/src/main/java/com/margelo/nitro/rive/BaseHybridViewModelPropertyImpl.kt +43 -24
- package/android/src/main/java/com/margelo/nitro/rive/HybridViewModelBooleanProperty.kt +3 -2
- package/android/src/main/java/com/margelo/nitro/rive/HybridViewModelColorProperty.kt +3 -2
- package/android/src/main/java/com/margelo/nitro/rive/HybridViewModelEnumProperty.kt +3 -2
- package/android/src/main/java/com/margelo/nitro/rive/HybridViewModelImageProperty.kt +3 -2
- package/android/src/main/java/com/margelo/nitro/rive/HybridViewModelNumberProperty.kt +3 -2
- package/android/src/main/java/com/margelo/nitro/rive/HybridViewModelStringProperty.kt +3 -2
- package/android/src/main/java/com/margelo/nitro/rive/HybridViewModelTriggerProperty.kt +3 -2
- package/ios/BaseHybridViewModelProperty.swift +13 -6
- package/ios/HybridViewModel.swift +1 -6
- package/ios/HybridViewModelBooleanProperty.swift +1 -9
- package/ios/HybridViewModelColorProperty.swift +3 -12
- package/ios/HybridViewModelEnumProperty.swift +1 -9
- package/ios/HybridViewModelImageProperty.swift +4 -4
- package/ios/HybridViewModelInstance.swift +1 -6
- package/ios/HybridViewModelNumberProperty.swift +2 -13
- package/ios/HybridViewModelStringProperty.swift +1 -9
- package/ios/HybridViewModelTriggerProperty.swift +5 -14
- package/ios/RiveReactNativeView.swift +36 -0
- package/lib/typescript/src/specs/ViewModel.nitro.d.ts +15 -15
- package/lib/typescript/src/specs/ViewModel.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHybridViewModelBooleanPropertySpec.cpp +14 -4
- package/nitrogen/generated/android/c++/JHybridViewModelBooleanPropertySpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridViewModelColorPropertySpec.cpp +14 -4
- package/nitrogen/generated/android/c++/JHybridViewModelColorPropertySpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridViewModelEnumPropertySpec.cpp +14 -4
- package/nitrogen/generated/android/c++/JHybridViewModelEnumPropertySpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridViewModelImagePropertySpec.cpp +15 -6
- package/nitrogen/generated/android/c++/JHybridViewModelImagePropertySpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridViewModelNumberPropertySpec.cpp +14 -4
- package/nitrogen/generated/android/c++/JHybridViewModelNumberPropertySpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridViewModelStringPropertySpec.cpp +14 -4
- package/nitrogen/generated/android/c++/JHybridViewModelStringPropertySpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridViewModelTriggerPropertySpec.cpp +12 -3
- package/nitrogen/generated/android/c++/JHybridViewModelTriggerPropertySpec.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/HybridViewModelBooleanPropertySpec.kt +3 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/HybridViewModelColorPropertySpec.kt +3 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/HybridViewModelEnumPropertySpec.kt +3 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/HybridViewModelImagePropertySpec.kt +3 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/HybridViewModelNumberPropertySpec.kt +3 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/HybridViewModelStringPropertySpec.kt +3 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/HybridViewModelTriggerPropertySpec.kt +3 -3
- package/nitrogen/generated/android/riveOnLoad.cpp +2 -74
- package/nitrogen/generated/ios/RNRive-Swift-Cxx-Bridge.hpp +9 -0
- package/nitrogen/generated/ios/RNRiveAutolinking.mm +0 -72
- package/nitrogen/generated/ios/RNRiveAutolinking.swift +0 -135
- package/nitrogen/generated/ios/c++/HybridViewModelBooleanPropertySpecSwift.hpp +3 -1
- package/nitrogen/generated/ios/c++/HybridViewModelColorPropertySpecSwift.hpp +3 -1
- package/nitrogen/generated/ios/c++/HybridViewModelEnumPropertySpecSwift.hpp +3 -1
- package/nitrogen/generated/ios/c++/HybridViewModelImagePropertySpecSwift.hpp +3 -1
- package/nitrogen/generated/ios/c++/HybridViewModelNumberPropertySpecSwift.hpp +3 -1
- package/nitrogen/generated/ios/c++/HybridViewModelStringPropertySpecSwift.hpp +3 -1
- package/nitrogen/generated/ios/c++/HybridViewModelTriggerPropertySpecSwift.hpp +3 -1
- package/nitrogen/generated/ios/swift/HybridViewModelBooleanPropertySpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridViewModelBooleanPropertySpec_cxx.swift +8 -4
- package/nitrogen/generated/ios/swift/HybridViewModelColorPropertySpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridViewModelColorPropertySpec_cxx.swift +8 -4
- package/nitrogen/generated/ios/swift/HybridViewModelEnumPropertySpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridViewModelEnumPropertySpec_cxx.swift +8 -4
- package/nitrogen/generated/ios/swift/HybridViewModelImagePropertySpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridViewModelImagePropertySpec_cxx.swift +8 -4
- package/nitrogen/generated/ios/swift/HybridViewModelNumberPropertySpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridViewModelNumberPropertySpec_cxx.swift +8 -4
- package/nitrogen/generated/ios/swift/HybridViewModelStringPropertySpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridViewModelStringPropertySpec_cxx.swift +8 -4
- package/nitrogen/generated/ios/swift/HybridViewModelTriggerPropertySpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridViewModelTriggerPropertySpec_cxx.swift +8 -4
- package/nitrogen/generated/shared/c++/HybridViewModelBooleanPropertySpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridViewModelColorPropertySpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridViewModelEnumPropertySpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridViewModelImagePropertySpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridViewModelNumberPropertySpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridViewModelStringPropertySpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridViewModelTriggerPropertySpec.hpp +1 -1
- package/package.json +1 -1
- package/src/hooks/useRiveProperty.ts +1 -1
- package/src/specs/ViewModel.nitro.ts +15 -15
|
@@ -9,12 +9,14 @@ import kotlinx.coroutines.flow.Flow
|
|
|
9
9
|
@Keep
|
|
10
10
|
@DoNotStrip
|
|
11
11
|
interface BaseHybridViewModelProperty<T> {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
val scope: CoroutineScope?
|
|
13
|
+
val job: Job?
|
|
14
|
+
val listeners: MutableMap<String, (T) -> Unit>
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
fun ensureValueListenerJob(valueFlow: Flow<T>, drop: Int = 0)
|
|
17
|
+
fun onChanged(value: T)
|
|
18
|
+
fun addListenerInternal(callback: (T) -> Unit): () -> Unit
|
|
19
|
+
fun removeListener(id: String)
|
|
20
|
+
fun removeListeners()
|
|
21
|
+
fun dispose()
|
|
20
22
|
}
|
|
@@ -9,42 +9,61 @@ import kotlinx.coroutines.cancel
|
|
|
9
9
|
import kotlinx.coroutines.launch
|
|
10
10
|
import kotlinx.coroutines.flow.Flow
|
|
11
11
|
import kotlinx.coroutines.flow.drop
|
|
12
|
+
import java.lang.ref.WeakReference
|
|
13
|
+
import java.util.UUID
|
|
12
14
|
|
|
13
15
|
@Keep
|
|
14
16
|
@DoNotStrip
|
|
15
17
|
class BaseHybridViewModelPropertyImpl<T> : BaseHybridViewModelProperty<T> {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
override var scope: CoroutineScope? = null
|
|
19
|
+
override var job: Job? = null
|
|
20
|
+
override val listeners = mutableMapOf<String, (T) -> Unit>()
|
|
19
21
|
|
|
20
22
|
override fun ensureValueListenerJob(valueFlow: Flow<T>, drop: Int) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
}
|
|
23
|
+
if (scope == null) {
|
|
24
|
+
scope = CoroutineScope(Dispatchers.Default)
|
|
25
|
+
}
|
|
26
|
+
if (job == null) {
|
|
27
|
+
job = scope?.launch {
|
|
28
|
+
valueFlow.drop(drop).collect { value ->
|
|
29
|
+
onChanged(value)
|
|
30
30
|
}
|
|
31
|
+
}
|
|
31
32
|
}
|
|
33
|
+
}
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
35
|
+
override fun onChanged(value: T) {
|
|
36
|
+
listeners.values.forEach { listener ->
|
|
37
|
+
listener(value)
|
|
37
38
|
}
|
|
39
|
+
}
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
override fun addListenerInternal(callback: (T) -> Unit): () -> Unit {
|
|
42
|
+
val id = UUID.randomUUID().toString()
|
|
43
|
+
listeners[id] = callback
|
|
44
|
+
val weakSelf = WeakReference(this)
|
|
45
|
+
return {
|
|
46
|
+
weakSelf.get()?.removeListener(id)
|
|
45
47
|
}
|
|
48
|
+
}
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
override fun removeListener(id: String) {
|
|
51
|
+
listeners.remove(id)
|
|
52
|
+
if (listeners.isEmpty()) {
|
|
53
|
+
job?.cancel()
|
|
54
|
+
job = null
|
|
49
55
|
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
override fun removeListeners() {
|
|
59
|
+
listeners.clear()
|
|
60
|
+
job?.cancel()
|
|
61
|
+
scope?.cancel()
|
|
62
|
+
job = null
|
|
63
|
+
scope = null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
override fun dispose() {
|
|
67
|
+
removeListeners()
|
|
68
|
+
}
|
|
50
69
|
}
|
|
@@ -15,8 +15,9 @@ class HybridViewModelBooleanProperty(private val viewModelBoolean: ViewModelBool
|
|
|
15
15
|
viewModelBoolean.value = value
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
override fun addListener(onChanged: (value: Boolean) -> Unit) {
|
|
19
|
-
|
|
18
|
+
override fun addListener(onChanged: (value: Boolean) -> Unit): () -> Unit {
|
|
19
|
+
val remover = addListenerInternal(onChanged)
|
|
20
20
|
ensureValueListenerJob(viewModelBoolean.valueFlow)
|
|
21
|
+
return remover
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -15,8 +15,9 @@ class HybridViewModelColorProperty(private val viewModelColor: ViewModelColorPro
|
|
|
15
15
|
viewModelColor.value = value.toInt()
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
override fun addListener(onChanged: (value: Double) -> Unit) {
|
|
19
|
-
|
|
18
|
+
override fun addListener(onChanged: (value: Double) -> Unit): () -> Unit {
|
|
19
|
+
val remover = addListenerInternal { intValue: Int -> onChanged(intValue.toDouble()) }
|
|
20
20
|
ensureValueListenerJob(viewModelColor.valueFlow)
|
|
21
|
+
return remover
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -15,8 +15,9 @@ class HybridViewModelEnumProperty(private val viewModelEnum: ViewModelEnumProper
|
|
|
15
15
|
viewModelEnum.value = value
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
override fun addListener(onChanged: (value: String) -> Unit) {
|
|
19
|
-
|
|
18
|
+
override fun addListener(onChanged: (value: String) -> Unit): () -> Unit {
|
|
19
|
+
val remover = addListenerInternal(onChanged)
|
|
20
20
|
ensureValueListenerJob(viewModelEnum.valueFlow)
|
|
21
|
+
return remover
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -14,8 +14,9 @@ class HybridViewModelImageProperty(private val viewModelImage: ViewModelImagePro
|
|
|
14
14
|
viewModelImage.set((image as? HybridRiveImage)?.renderImage)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
override fun addListener(onChanged: () -> Unit) {
|
|
18
|
-
|
|
17
|
+
override fun addListener(onChanged: () -> Unit): () -> Unit {
|
|
18
|
+
val remover = addListenerInternal { _ -> onChanged() }
|
|
19
19
|
ensureValueListenerJob(viewModelImage.valueFlow.map { })
|
|
20
|
+
return remover
|
|
20
21
|
}
|
|
21
22
|
}
|
|
@@ -16,8 +16,9 @@ class HybridViewModelNumberProperty(private val viewModelNumber: ViewModelNumber
|
|
|
16
16
|
viewModelNumber.value = value.toFloat()
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
override fun addListener(onChanged: (value: Double) -> Unit) {
|
|
20
|
-
|
|
19
|
+
override fun addListener(onChanged: (value: Double) -> Unit): () -> Unit {
|
|
20
|
+
val remover = addListenerInternal(onChanged)
|
|
21
21
|
ensureValueListenerJob(viewModelNumber.valueFlow.map { it.toDouble() })
|
|
22
|
+
return remover
|
|
22
23
|
}
|
|
23
24
|
}
|
|
@@ -15,8 +15,9 @@ class HybridViewModelStringProperty(private val viewModelString: ViewModelString
|
|
|
15
15
|
viewModelString.value = value
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
override fun addListener(onChanged: (value: String) -> Unit) {
|
|
19
|
-
|
|
18
|
+
override fun addListener(onChanged: (value: String) -> Unit): () -> Unit {
|
|
19
|
+
val remover = addListenerInternal(onChanged)
|
|
20
20
|
ensureValueListenerJob(viewModelString.valueFlow)
|
|
21
|
+
return remover
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -13,9 +13,10 @@ class HybridViewModelTriggerProperty(private val viewModelTrigger: ViewModelTrig
|
|
|
13
13
|
viewModelTrigger.trigger()
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
override fun addListener(onChanged: () -> Unit) {
|
|
17
|
-
|
|
16
|
+
override fun addListener(onChanged: () -> Unit): () -> Unit {
|
|
17
|
+
val remover = addListenerInternal { _ -> onChanged() }
|
|
18
18
|
// We drop the first value as a trigger has no initial value
|
|
19
19
|
ensureValueListenerJob(viewModelTrigger.valueFlow, 1)
|
|
20
|
+
return remover
|
|
20
21
|
}
|
|
21
22
|
}
|
|
@@ -65,11 +65,18 @@ class PropertyListenerHelper<PropertyType: RivePropertyWithListeners> {
|
|
|
65
65
|
self.property = property
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
/// Adds a listener to the property and
|
|
69
|
-
func addListener(_ callback: @escaping (PropertyType.ListenerValueType) -> Void) {
|
|
70
|
-
guard let property = property else {
|
|
68
|
+
/// Adds a listener to the property and returns a removal function for cleanup
|
|
69
|
+
func addListener(_ callback: @escaping (PropertyType.ListenerValueType) -> Void) -> () -> Void {
|
|
70
|
+
guard let property = property else {
|
|
71
|
+
return {}
|
|
72
|
+
}
|
|
71
73
|
let id = property.addListener(callback)
|
|
72
74
|
listenerIds.append(id)
|
|
75
|
+
return { [weak self, weak property] in
|
|
76
|
+
guard let property = property else { return }
|
|
77
|
+
property.removeListener(id)
|
|
78
|
+
self?.listenerIds.removeAll { $0 == id }
|
|
79
|
+
}
|
|
73
80
|
}
|
|
74
81
|
|
|
75
82
|
func removeListeners() throws {
|
|
@@ -94,7 +101,7 @@ protocol ValuedPropertyProtocol<ValueType> {
|
|
|
94
101
|
var property: PropertyType! { get }
|
|
95
102
|
var helper: PropertyListenerHelper<PropertyType> { get }
|
|
96
103
|
|
|
97
|
-
func addListener(onChanged: @escaping (ValueType) -> Void) throws
|
|
104
|
+
func addListener(onChanged: @escaping (ValueType) -> Void) throws -> () -> Void
|
|
98
105
|
func removeListeners() throws
|
|
99
106
|
func dispose() throws
|
|
100
107
|
}
|
|
@@ -112,7 +119,7 @@ extension ValuedPropertyProtocol {
|
|
|
112
119
|
|
|
113
120
|
/// Automatic addListener() ONLY when ListenerValueType == ValueType (no conversion needed)
|
|
114
121
|
extension ValuedPropertyProtocol where PropertyType.ListenerValueType == ValueType {
|
|
115
|
-
func addListener(onChanged: @escaping (ValueType) -> Void) throws {
|
|
116
|
-
helper.addListener(onChanged)
|
|
122
|
+
func addListener(onChanged: @escaping (ValueType) -> Void) throws -> () -> Void {
|
|
123
|
+
return helper.addListener(onChanged)
|
|
117
124
|
}
|
|
118
125
|
}
|
|
@@ -6,12 +6,7 @@ class HybridViewModel: HybridViewModelSpec {
|
|
|
6
6
|
init(viewModel: RiveDataBindingViewModel) {
|
|
7
7
|
self.viewModel = viewModel
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
override init() {
|
|
11
|
-
self.viewModel = nil
|
|
12
|
-
super.init()
|
|
13
|
-
}
|
|
14
|
-
|
|
9
|
+
|
|
15
10
|
var propertyCount: Double { Double(viewModel?.propertyCount ?? 0) }
|
|
16
11
|
|
|
17
12
|
var instanceCount: Double { Double(viewModel?.instanceCount ?? 0) }
|
|
@@ -9,15 +9,7 @@ class HybridViewModelBooleanProperty: HybridViewModelBooleanPropertySpec, Valued
|
|
|
9
9
|
self.property = property
|
|
10
10
|
super.init()
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
/// ⚠️ DO NOT REMOVE
|
|
14
|
-
/// Nitro requires a parameterless initializer for JS bridging.
|
|
15
|
-
/// This is invoked automatically during hybrid module construction.
|
|
16
|
-
/// Internally we always use `init(property:)`
|
|
17
|
-
override init() {
|
|
18
|
-
super.init()
|
|
19
|
-
}
|
|
20
|
-
|
|
12
|
+
|
|
21
13
|
var value: Bool {
|
|
22
14
|
get {
|
|
23
15
|
return property.value
|
|
@@ -9,15 +9,7 @@ class HybridViewModelColorProperty: HybridViewModelColorPropertySpec, ValuedProp
|
|
|
9
9
|
self.property = property
|
|
10
10
|
super.init()
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
/// ⚠️ DO NOT REMOVE
|
|
14
|
-
/// Nitro requires a parameterless initializer for JS bridging.
|
|
15
|
-
/// This is invoked automatically during hybrid module construction.
|
|
16
|
-
/// Internally we always use `init(property:)`
|
|
17
|
-
override init() {
|
|
18
|
-
super.init()
|
|
19
|
-
}
|
|
20
|
-
|
|
12
|
+
|
|
21
13
|
var value: Double {
|
|
22
14
|
get {
|
|
23
15
|
return property.value.toHexDouble()
|
|
@@ -27,9 +19,8 @@ class HybridViewModelColorProperty: HybridViewModelColorPropertySpec, ValuedProp
|
|
|
27
19
|
}
|
|
28
20
|
}
|
|
29
21
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
helper.addListener { (color: UIColor) in
|
|
22
|
+
func addListener(onChanged: @escaping (Double) -> Void) throws -> () -> Void {
|
|
23
|
+
return helper.addListener { (color: UIColor) in
|
|
33
24
|
onChanged(color.toHexDouble())
|
|
34
25
|
}
|
|
35
26
|
}
|
|
@@ -9,15 +9,7 @@ class HybridViewModelEnumProperty: HybridViewModelEnumPropertySpec, ValuedProper
|
|
|
9
9
|
self.property = property
|
|
10
10
|
super.init()
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
/// ⚠️ DO NOT REMOVE
|
|
14
|
-
/// Nitro requires a parameterless initializer for JS bridging.
|
|
15
|
-
/// This is invoked automatically during hybrid module construction.
|
|
16
|
-
/// Internally we always use `init(property:)`
|
|
17
|
-
override init() {
|
|
18
|
-
super.init()
|
|
19
|
-
}
|
|
20
|
-
|
|
12
|
+
|
|
21
13
|
var value: String {
|
|
22
14
|
get {
|
|
23
15
|
return property.value
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import RiveRuntime
|
|
2
2
|
|
|
3
3
|
class HybridViewModelImageProperty: HybridViewModelImagePropertySpec, ValuedPropertyProtocol {
|
|
4
|
-
func addListener(onChanged: @escaping () -> Void) throws {
|
|
5
|
-
try addListener(onChanged: { _ in onChanged() })
|
|
6
|
-
}
|
|
7
|
-
|
|
8
4
|
var property: ImagePropertyType!
|
|
9
5
|
lazy var helper = PropertyListenerHelper(property: property!)
|
|
10
6
|
|
|
7
|
+
func addListener(onChanged: @escaping () -> Void) throws -> () -> Void {
|
|
8
|
+
return helper.addListener { _ in onChanged() }
|
|
9
|
+
}
|
|
10
|
+
|
|
11
11
|
init(property: ImagePropertyType) {
|
|
12
12
|
self.property = property
|
|
13
13
|
super.init()
|
|
@@ -6,12 +6,7 @@ class HybridViewModelInstance: HybridViewModelInstanceSpec {
|
|
|
6
6
|
init(viewModelInstance: RiveDataBindingViewModel.Instance) {
|
|
7
7
|
self.viewModelInstance = viewModelInstance
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
override init() {
|
|
11
|
-
self.viewModelInstance = nil
|
|
12
|
-
super.init()
|
|
13
|
-
}
|
|
14
|
-
|
|
9
|
+
|
|
15
10
|
var instanceName: String { viewModelInstance?.name ?? "" }
|
|
16
11
|
|
|
17
12
|
func numberProperty(path: String) throws -> (any HybridViewModelNumberPropertySpec)? {
|
|
@@ -9,14 +9,6 @@ class HybridViewModelNumberProperty: HybridViewModelNumberPropertySpec, ValuedPr
|
|
|
9
9
|
super.init()
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
/// ⚠️ DO NOT REMOVE
|
|
13
|
-
/// Nitro requires a parameterless initializer for JS bridging.
|
|
14
|
-
/// This is invoked automatically during hybrid module construction.
|
|
15
|
-
/// Internally we always use `init(property:)`
|
|
16
|
-
override init() {
|
|
17
|
-
super.init()
|
|
18
|
-
}
|
|
19
|
-
|
|
20
12
|
var value: Double {
|
|
21
13
|
get {
|
|
22
14
|
return Double(property.value)
|
|
@@ -26,10 +18,7 @@ class HybridViewModelNumberProperty: HybridViewModelNumberPropertySpec, ValuedPr
|
|
|
26
18
|
}
|
|
27
19
|
}
|
|
28
20
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
helper.addListener { (value: Float) in
|
|
32
|
-
onChanged(Double(value))
|
|
33
|
-
}
|
|
21
|
+
func addListener(onChanged: @escaping (Double) -> Void) throws -> () -> Void {
|
|
22
|
+
return helper.addListener({ floatValue in onChanged(Double(floatValue)) })
|
|
34
23
|
}
|
|
35
24
|
}
|
|
@@ -9,15 +9,7 @@ class HybridViewModelStringProperty: HybridViewModelStringPropertySpec, ValuedPr
|
|
|
9
9
|
self.property = property
|
|
10
10
|
super.init()
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
/// ⚠️ DO NOT REMOVE
|
|
14
|
-
/// Nitro requires a parameterless initializer for JS bridging.
|
|
15
|
-
/// This is invoked automatically during hybrid module construction.
|
|
16
|
-
/// Internally we always use `init(property:)`
|
|
17
|
-
override init() {
|
|
18
|
-
super.init()
|
|
19
|
-
}
|
|
20
|
-
|
|
12
|
+
|
|
21
13
|
var value: String {
|
|
22
14
|
get {
|
|
23
15
|
return property.value
|
|
@@ -4,27 +4,18 @@ import RiveRuntime
|
|
|
4
4
|
class HybridViewModelTriggerProperty: HybridViewModelTriggerPropertySpec, ValuedPropertyProtocol {
|
|
5
5
|
internal var property: TriggerPropertyType!
|
|
6
6
|
lazy var helper = PropertyListenerHelper(property: property!)
|
|
7
|
-
|
|
8
7
|
private var listenerIds: [UUID] = []
|
|
9
8
|
|
|
10
|
-
func addListener(onChanged: @escaping () -> Void) throws {
|
|
11
|
-
try addListener(onChanged: { _ in onChanged() })
|
|
12
|
-
}
|
|
13
|
-
|
|
14
9
|
init(property: TriggerPropertyType) {
|
|
15
10
|
self.property = property
|
|
16
11
|
super.init()
|
|
17
12
|
}
|
|
18
|
-
|
|
19
|
-
/// ⚠️ DO NOT REMOVE
|
|
20
|
-
/// Nitro requires a parameterless initializer for JS bridging.
|
|
21
|
-
/// This is invoked automatically during hybrid module construction.
|
|
22
|
-
/// Internally we always use `init(property:)`
|
|
23
|
-
override init() {
|
|
24
|
-
super.init()
|
|
25
|
-
}
|
|
26
|
-
|
|
13
|
+
|
|
27
14
|
func trigger() {
|
|
28
15
|
property.trigger()
|
|
29
16
|
}
|
|
17
|
+
|
|
18
|
+
func addListener(onChanged: @escaping () -> Void) throws -> () -> Void {
|
|
19
|
+
try addListener(onChanged: { _ in onChanged() })
|
|
20
|
+
}
|
|
30
21
|
}
|
|
@@ -58,6 +58,8 @@ class RiveReactNativeView: UIView, RiveStateMachineDelegate {
|
|
|
58
58
|
func configure(_ config: ViewConfiguration, dataBindingChanged: Bool = false, reload: Bool = false, initialUpdate: Bool = false) throws {
|
|
59
59
|
if reload {
|
|
60
60
|
cleanup()
|
|
61
|
+
try validateConfiguration(config)
|
|
62
|
+
|
|
61
63
|
let model = RiveModel(riveFile: config.riveFile)
|
|
62
64
|
baseViewModel = RiveViewModel(model, stateMachineName: config.stateMachineName, autoPlay: config.autoPlay, artboardName: config.artboardName)
|
|
63
65
|
createViewFromViewModel()
|
|
@@ -322,4 +324,38 @@ class RiveReactNativeView: UIView, RiveStateMachineDelegate {
|
|
|
322
324
|
|
|
323
325
|
return try onSuccess(input)
|
|
324
326
|
}
|
|
327
|
+
|
|
328
|
+
private func validateConfiguration(_ config: ViewConfiguration) throws {
|
|
329
|
+
try validateArtboardName(config.artboardName, in: config.riveFile)
|
|
330
|
+
try validateStateMachineName(config.stateMachineName, artboardName: config.artboardName, in: config.riveFile)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
private func validateArtboardName(_ artboardName: String?, in riveFile: RiveFile) throws {
|
|
334
|
+
guard let artboardName = artboardName else { return }
|
|
335
|
+
let artboardNames = riveFile.artboardNames()
|
|
336
|
+
if !artboardNames.contains(artboardName) {
|
|
337
|
+
throw NSError(
|
|
338
|
+
domain: RiveErrorDomain,
|
|
339
|
+
code: Int(RiveErrorCode.noArtboardFound.rawValue),
|
|
340
|
+
userInfo: [NSLocalizedDescriptionKey: "Artboard '\(artboardName)' not found. Available: \(artboardNames.joined(separator: ", "))"]
|
|
341
|
+
)
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
private func validateStateMachineName(_ stateMachineName: String?, artboardName: String?, in riveFile: RiveFile) throws {
|
|
346
|
+
guard let stateMachineName = stateMachineName else { return }
|
|
347
|
+
let artboard = artboardName != nil
|
|
348
|
+
? try? riveFile.artboard(fromName: artboardName!)
|
|
349
|
+
: try? riveFile.artboard()
|
|
350
|
+
|
|
351
|
+
guard let artboard = artboard else { return }
|
|
352
|
+
let stateMachineNames = artboard.stateMachineNames()
|
|
353
|
+
if !stateMachineNames.contains(stateMachineName) {
|
|
354
|
+
throw NSError(
|
|
355
|
+
domain: RiveErrorDomain,
|
|
356
|
+
code: Int(RiveErrorCode.noStateMachineFound.rawValue),
|
|
357
|
+
userInfo: [NSLocalizedDescriptionKey: "State machine '\(stateMachineName)' not found. Available: \(stateMachineNames.joined(separator: ", "))"]
|
|
358
|
+
)
|
|
359
|
+
}
|
|
360
|
+
}
|
|
325
361
|
}
|
|
@@ -55,49 +55,49 @@ export interface ViewModelProperty extends HybridObject<{
|
|
|
55
55
|
}> {
|
|
56
56
|
}
|
|
57
57
|
export interface ObservableProperty {
|
|
58
|
-
/** Remove all listeners from the
|
|
58
|
+
/** Remove all listeners from the property */
|
|
59
59
|
removeListeners(): void;
|
|
60
60
|
}
|
|
61
61
|
export interface ViewModelNumberProperty extends ViewModelProperty, ObservableProperty {
|
|
62
62
|
/** The value of the view model number property */
|
|
63
63
|
value: number;
|
|
64
|
-
/** Add a listener to the view model number property */
|
|
65
|
-
addListener(onChanged: (value: number) => void): void;
|
|
64
|
+
/** Add a listener to the view model number property. Returns a function to remove the listener. */
|
|
65
|
+
addListener(onChanged: (value: number) => void): () => void;
|
|
66
66
|
}
|
|
67
67
|
export interface ViewModelStringProperty extends ViewModelProperty, ObservableProperty {
|
|
68
68
|
/** The value of the view model string property */
|
|
69
69
|
value: string;
|
|
70
|
-
/** Add a listener to the view model string property */
|
|
71
|
-
addListener(onChanged: (value: string) => void): void;
|
|
70
|
+
/** Add a listener to the view model string property. Returns a function to remove the listener. */
|
|
71
|
+
addListener(onChanged: (value: string) => void): () => void;
|
|
72
72
|
}
|
|
73
73
|
export interface ViewModelBooleanProperty extends ViewModelProperty, ObservableProperty {
|
|
74
74
|
/** The value of the view model boolean property */
|
|
75
75
|
value: boolean;
|
|
76
|
-
/** Add a listener to the view model boolean property */
|
|
77
|
-
addListener(onChanged: (value: boolean) => void): void;
|
|
76
|
+
/** Add a listener to the view model boolean property. Returns a function to remove the listener. */
|
|
77
|
+
addListener(onChanged: (value: boolean) => void): () => void;
|
|
78
78
|
}
|
|
79
79
|
export interface ViewModelColorProperty extends ViewModelProperty, ObservableProperty {
|
|
80
80
|
/** The value of the view model color property */
|
|
81
81
|
value: number;
|
|
82
|
-
/** Add a listener to the view model color property */
|
|
83
|
-
addListener(onChanged: (value: number) => void): void;
|
|
82
|
+
/** Add a listener to the view model color property. Returns a function to remove the listener. */
|
|
83
|
+
addListener(onChanged: (value: number) => void): () => void;
|
|
84
84
|
}
|
|
85
85
|
export interface ViewModelEnumProperty extends ViewModelProperty, ObservableProperty {
|
|
86
86
|
/** The value of the view model enum property */
|
|
87
87
|
value: string;
|
|
88
|
-
/** Add a listener to the view model enum property */
|
|
89
|
-
addListener(onChanged: (value: string) => void): void;
|
|
88
|
+
/** Add a listener to the view model enum property. Returns a function to remove the listener. */
|
|
89
|
+
addListener(onChanged: (value: string) => void): () => void;
|
|
90
90
|
}
|
|
91
91
|
export interface ViewModelTriggerProperty extends ViewModelProperty, ObservableProperty {
|
|
92
|
-
/** Add a listener to the view model trigger property */
|
|
93
|
-
addListener(onChanged: () => void): void;
|
|
92
|
+
/** Add a listener to the view model trigger property. Returns a function to remove the listener. */
|
|
93
|
+
addListener(onChanged: () => void): () => void;
|
|
94
94
|
/** Trigger the view model trigger property */
|
|
95
95
|
trigger(): void;
|
|
96
96
|
}
|
|
97
97
|
export interface ViewModelImageProperty extends ViewModelProperty, ObservableProperty {
|
|
98
98
|
/** Set the image property value */
|
|
99
99
|
set(image: RiveImage | undefined): void;
|
|
100
|
-
/** Add a listener to the view model image property */
|
|
101
|
-
addListener(onChanged: () => void): void;
|
|
100
|
+
/** Add a listener to the view model image property. Returns a function to remove the listener. */
|
|
101
|
+
addListener(onChanged: () => void): () => void;
|
|
102
102
|
}
|
|
103
103
|
//# sourceMappingURL=ViewModel.nitro.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ViewModel.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/ViewModel.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;;GAGG;AACH,MAAM,WAAW,SACf,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC;IACzD,iDAAiD;IACjD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,2DAA2D;IAC3D,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,iCAAiC;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,uDAAuD;IACvD,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAAC;IACpE,sDAAsD;IACtD,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAAC;IAClE,oDAAoD;IACpD,qBAAqB,IAAI,iBAAiB,GAAG,SAAS,CAAC;IACvD,8CAA8C;IAC9C,cAAc,IAAI,iBAAiB,GAAG,SAAS,CAAC;CACjD;AAED;;;;GAIG;AACH,MAAM,WAAW,iBACf,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC;IACzD,0CAA0C;IAC1C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,2EAA2E;IAC3E,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,uBAAuB,GAAG,SAAS,CAAC;IAElE,2EAA2E;IAC3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AAM,WAAW,sBACf,SAAQ,iBAAiB,EACvB,kBAAkB;IACpB,mCAAmC;IACnC,GAAG,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC;IACxC,kGAAkG;IAClG,WAAW,CAAC,SAAS,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;CAChD"}
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
#include <functional>
|
|
13
|
-
#include "
|
|
13
|
+
#include "JFunc_void.hpp"
|
|
14
14
|
#include <NitroModules/JNICallable.hpp>
|
|
15
|
+
#include "JFunc_void_bool.hpp"
|
|
15
16
|
|
|
16
17
|
namespace margelo::nitro::rive {
|
|
17
18
|
|
|
@@ -53,9 +54,18 @@ namespace margelo::nitro::rive {
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
// Methods
|
|
56
|
-
void JHybridViewModelBooleanPropertySpec::addListener(const std::function<void(bool /* value */)>& onChanged) {
|
|
57
|
-
static const auto method = javaClassStatic()->getMethod<
|
|
58
|
-
method(_javaPart, JFunc_void_bool_cxx::fromCpp(onChanged));
|
|
57
|
+
std::function<void()> JHybridViewModelBooleanPropertySpec::addListener(const std::function<void(bool /* value */)>& onChanged) {
|
|
58
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JFunc_void::javaobject>(jni::alias_ref<JFunc_void_bool::javaobject> /* onChanged */)>("addListener_cxx");
|
|
59
|
+
auto __result = method(_javaPart, JFunc_void_bool_cxx::fromCpp(onChanged));
|
|
60
|
+
return [&]() -> std::function<void()> {
|
|
61
|
+
if (__result->isInstanceOf(JFunc_void_cxx::javaClassStatic())) [[likely]] {
|
|
62
|
+
auto downcast = jni::static_ref_cast<JFunc_void_cxx::javaobject>(__result);
|
|
63
|
+
return downcast->cthis()->getFunction();
|
|
64
|
+
} else {
|
|
65
|
+
auto __resultRef = jni::make_global(__result);
|
|
66
|
+
return JNICallable<JFunc_void, void()>(std::move(__resultRef));
|
|
67
|
+
}
|
|
68
|
+
}();
|
|
59
69
|
}
|
|
60
70
|
void JHybridViewModelBooleanPropertySpec::removeListeners() {
|
|
61
71
|
static const auto method = javaClassStatic()->getMethod<void()>("removeListeners");
|
|
@@ -56,7 +56,7 @@ namespace margelo::nitro::rive {
|
|
|
56
56
|
|
|
57
57
|
public:
|
|
58
58
|
// Methods
|
|
59
|
-
void addListener(const std::function<void(bool /* value */)>& onChanged) override;
|
|
59
|
+
std::function<void()> addListener(const std::function<void(bool /* value */)>& onChanged) override;
|
|
60
60
|
void removeListeners() override;
|
|
61
61
|
|
|
62
62
|
private:
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
#include <functional>
|
|
13
|
-
#include "
|
|
13
|
+
#include "JFunc_void.hpp"
|
|
14
14
|
#include <NitroModules/JNICallable.hpp>
|
|
15
|
+
#include "JFunc_void_double.hpp"
|
|
15
16
|
|
|
16
17
|
namespace margelo::nitro::rive {
|
|
17
18
|
|
|
@@ -53,9 +54,18 @@ namespace margelo::nitro::rive {
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
// Methods
|
|
56
|
-
void JHybridViewModelColorPropertySpec::addListener(const std::function<void(double /* value */)>& onChanged) {
|
|
57
|
-
static const auto method = javaClassStatic()->getMethod<
|
|
58
|
-
method(_javaPart, JFunc_void_double_cxx::fromCpp(onChanged));
|
|
57
|
+
std::function<void()> JHybridViewModelColorPropertySpec::addListener(const std::function<void(double /* value */)>& onChanged) {
|
|
58
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JFunc_void::javaobject>(jni::alias_ref<JFunc_void_double::javaobject> /* onChanged */)>("addListener_cxx");
|
|
59
|
+
auto __result = method(_javaPart, JFunc_void_double_cxx::fromCpp(onChanged));
|
|
60
|
+
return [&]() -> std::function<void()> {
|
|
61
|
+
if (__result->isInstanceOf(JFunc_void_cxx::javaClassStatic())) [[likely]] {
|
|
62
|
+
auto downcast = jni::static_ref_cast<JFunc_void_cxx::javaobject>(__result);
|
|
63
|
+
return downcast->cthis()->getFunction();
|
|
64
|
+
} else {
|
|
65
|
+
auto __resultRef = jni::make_global(__result);
|
|
66
|
+
return JNICallable<JFunc_void, void()>(std::move(__resultRef));
|
|
67
|
+
}
|
|
68
|
+
}();
|
|
59
69
|
}
|
|
60
70
|
void JHybridViewModelColorPropertySpec::removeListeners() {
|
|
61
71
|
static const auto method = javaClassStatic()->getMethod<void()>("removeListeners");
|