Skip to content

Commit 1b52b51

Browse files
authored
fix: only rebind if view model prop is different (#51)
1 parent d7c90db commit 1b52b51

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

ios/HybridRiveView.swift

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,41 @@ where Wrapped == HybridDataBindMode {
3737
return .byName(dataBindByName.byName)
3838
}
3939
}
40+
41+
/// Check if two HybridDataBindMode values are semantically equal
42+
func isEqual(to other: HybridDataBindMode?) -> Bool {
43+
guard let lhs = self, let rhs = other else {
44+
return self == nil && other == nil
45+
}
46+
47+
switch (lhs, rhs) {
48+
case (.first(let lhsInstance), .first(let rhsInstance)):
49+
// Compare ViewModelInstance references
50+
let lhsVMI = (lhsInstance as? HybridViewModelInstance)?.viewModelInstance
51+
let rhsVMI = (rhsInstance as? HybridViewModelInstance)?.viewModelInstance
52+
return lhsVMI === rhsVMI
53+
54+
case (.second(let lhsMode), .second(let rhsMode)):
55+
// Compare DataBindMode enums
56+
return lhsMode == rhsMode
57+
58+
case (.third(let lhsByName), .third(let rhsByName)):
59+
// Compare byName strings
60+
return lhsByName.byName == rhsByName.byName
61+
62+
default:
63+
return false
64+
}
65+
}
4066
}
4167

4268
class HybridRiveView: HybridRiveViewSpec {
4369
// MARK: View Props
4470
var dataBind: HybridDataBindMode? = nil {
4571
didSet {
46-
dataBindingChanged = true
72+
if !dataBind.isEqual(to: oldValue) {
73+
dataBindingChanged = true
74+
}
4775
}
4876
}
4977

0 commit comments

Comments
 (0)