Skip to content

Commit 2f17127

Browse files
committed
fix: handle swap returning void in native SDKs, fix listeners lambda
1 parent 054e110 commit 2f17127

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

android/src/main/java/com/margelo/nitro/rive/HybridViewModelListProperty.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@ class HybridViewModelListProperty(private val listProperty: ViewModelListPropert
4747
}
4848

4949
override fun swap(index1: Double, index2: Double): Boolean {
50-
return listProperty.swap(index1.toInt(), index2.toInt())
50+
val idx1 = index1.toInt()
51+
val idx2 = index2.toInt()
52+
if (idx1 < 0 || idx1 >= listProperty.size || idx2 < 0 || idx2 >= listProperty.size) {
53+
return false
54+
}
55+
listProperty.swap(idx1, idx2)
56+
return true
5157
}
5258

5359
override fun addListener(onChanged: () -> Unit) {
54-
listeners.add { _ -> onChanged() }
60+
listeners.add { onChanged() }
5561
ensureValueListenerJob(listProperty.valueFlow.map { })
5662
}
5763
}

ios/HybridViewModelListProperty.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ class HybridViewModelListProperty: HybridViewModelListPropertySpec, ValuedProper
4747
}
4848

4949
func swap(index1: Double, index2: Double) throws -> Bool {
50-
return property.swap(at: UInt32(index1), with: UInt32(index2))
50+
let idx1 = UInt32(index1)
51+
let idx2 = UInt32(index2)
52+
guard idx1 < property.count && idx2 < property.count else {
53+
return false
54+
}
55+
property.swap(at: idx1, with: idx2)
56+
return true
5157
}
5258

5359
func addListener(onChanged: @escaping () -> Void) throws {

0 commit comments

Comments
 (0)