Skip to content

Commit aabde02

Browse files
committed
fix: dataBindingChanged
1 parent 78599a8 commit aabde02

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

ios/HybridRiveView.swift

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class HybridRiveView: HybridRiveViewSpec {
4343
// MARK: View Props
4444
var dataBind: HybridDataBindMode? = nil {
4545
didSet {
46-
applyDataBinding()
46+
dataBindingChanged = true
4747
}
4848
}
4949
var artboardName: String? { didSet { needsReload = true } }
@@ -120,18 +120,8 @@ class HybridRiveView: HybridRiveViewSpec {
120120
return riveView
121121
}
122122

123-
// MARK: Data Binding
124-
private func applyDataBinding() {
125-
logged(tag: "HybridRiveView", note: "applyDataBinding") {
126-
guard let riveView = view as? RiveReactNativeView else { return }
127-
let bindData = try dataBind.toDataBingMode()
128-
riveView.applyDataBinding(bindData, refresh: !firstUpdate)
129-
}
130-
}
131-
132123
// MARK: Update
133124
func afterUpdate() {
134-
firstUpdate = false
135125
logged(tag: "HybridRiveView", note: "afterUpdate") {
136126
guard let hybridFile = file as? HybridRiveFile,
137127
let file = hybridFile.riveFile
@@ -149,14 +139,15 @@ class HybridRiveView: HybridRiveViewSpec {
149139
bindData: try dataBind.toDataBingMode()
150140
)
151141

152-
try getRiveView().configure(config, reload: needsReload)
142+
try getRiveView().configure(config, dataBindingChanged: dataBindingChanged, reload: needsReload)
153143
needsReload = false
144+
dataBindingChanged = false
154145
}
155146
}
156147

157148
// MARK: Internal State
158-
private var firstUpdate = true
159149
private var needsReload = false
150+
private var dataBindingChanged = false
160151

161152
// MARK: Helpers
162153
private func convertAlignment(_ alignment: Alignment?) -> RiveAlignment? {

ios/RiveReactNativeView.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class RiveReactNativeView: UIView, RiveStateMachineDelegate {
3232
private var baseViewModel: RiveViewModel?
3333
private var eventListeners: [(UnifiedRiveEvent) -> Void] = []
3434
private var viewReadyContinuation: CheckedContinuation<Void, Never>?
35-
private var isFirstConfigure = true
3635
private var isViewReady = false
3736
private weak var viewSource: RiveViewSource?
3837

@@ -51,7 +50,7 @@ class RiveReactNativeView: UIView, RiveStateMachineDelegate {
5150
return true
5251
}
5352

54-
func configure(_ config: ViewConfiguration, reload: Bool = false) {
53+
func configure(_ config: ViewConfiguration, dataBindingChanged: Bool = false, reload: Bool = false) {
5554
if reload {
5655
cleanup()
5756
let model = RiveModel(riveFile: config.riveFile)
@@ -75,7 +74,9 @@ class RiveReactNativeView: UIView, RiveStateMachineDelegate {
7574
viewReadyContinuation = nil
7675
}
7776

78-
applyDataBinding(config.bindData, refresh: false)
77+
if dataBindingChanged {
78+
applyDataBinding(config.bindData)
79+
}
7980
}
8081

8182
func bindViewModelInstance(viewModelInstance: RiveDataBindingViewModel.Instance) {
@@ -86,7 +87,7 @@ class RiveReactNativeView: UIView, RiveStateMachineDelegate {
8687
return baseViewModel?.riveModel?.stateMachine?.viewModelInstance
8788
}
8889

89-
func applyDataBinding(_ bindData: BindData, refresh: Bool = false) {
90+
func applyDataBinding(_ bindData: BindData) {
9091
let stateMachine = baseViewModel?.riveModel?.stateMachine
9192
let artboard = baseViewModel?.riveModel?.artboard
9293

@@ -115,9 +116,7 @@ class RiveReactNativeView: UIView, RiveStateMachineDelegate {
115116
stateMachine?.bind(viewModelInstance: instance)
116117
artboard?.bind(viewModelInstance: instance)
117118
}
118-
if refresh {
119-
baseViewModel?.play()
120-
}
119+
baseViewModel?.play()
121120
}
122121

123122
func play() {

0 commit comments

Comments
 (0)