✅ Solved: iOS Data Binding Triggers - Only work when clicked
Hi there,
I have tried to simplify my example but effectively I have a rive file which is using data binding. Inside the view model I have some triggers that are used to progress the animation. Testing these in the rive editor works and even exporting them and using them in react (with autobinding) also works. But for some reason on iOS the animation will only recognise the trigger after I click on the animation ?
I might be doing something silly - but I made it simpler by making a file that just has a red circle and two triggers in the view model, one to move it up and one to move it down. And the same thing happens, it works in react fine but not iOS unless I click the animation. Not sure why this happens?
I have attached my rive file and the examples in iOS and react
Here is my code
import SwiftUI
import RiveRuntime
private class VMIBox {
var instance: RiveDataBindingViewModel.Instance?
}
struct ContentView: View {
var riveViewModel = RiveViewModel(fileName: "ios", autoPlay: true)
@State private var vmiBox = VMIBox()
var body: some View {
VStack {
riveViewModel.view()
Text("This is the box game")
Button("Up") {
vmiBox.instance?
.triggerProperty(fromPath: "up")?
.trigger()
}
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
Button("Down") {
// try not using stored instance
riveViewModel.riveModel?.stateMachine?.viewModelInstance?
.triggerProperty(fromPath: "down")?
.trigger()
}
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
}
.padding()
.onAppear(perform: setupAutoBind)
}
private func setupAutoBind() {
riveViewModel.riveModel?.enableAutoBind { instance in
vmiBox.instance = instance
}
}
}