updating artboard databind from code (viewModelInstance) not working on IOS runtime (SwiftUI)
I’m currently working on a proof of concept to understand how our studio could use Rive as an engine (for our in game events). One of the core concepts is to be able to dynamically swap some UI elements, which are built using Rive nested artboards, via data binding on an artboard property in the viewModel.
I have set up a test to validate this mechanism but when I update the artboard property in swift code (using bindable artboard) and call rive.play(), the view simply goes blank. As a test I included listeners on the stateMachine in my .riv file to test that if I tap the rectangle triggers, the artboard property update from within the .riv file via the listener it works in my app.
The problem seems to be with programmatically updating the databind property from swift code - any help/guidance would be greatly appreciated !
Snippet for instantiation:
Button {
rive = RiveViewModel(fileName: "event_-_ui", artboardName: "View")
rive?.riveModel?.enableAutoBind { instance in
let selector = instance.stringProperty(fromPath: "selection")
selector?.addListener { newValue in
DispatchQueue.main.async {
selection = newValue
}
}
let board = instance.artboardProperty(fromPath: "board")
board?.addListener {
print("board changed")
}
self.instance = instance
initialised = true
}
} label: {
Text("Load inital")
}Snippet for databind update:
Button {
let file = try? RiveFile(resource: "event_-_ui", loadCdn: false)
let name = !bool ? "dialog" : "locked"
if let obj = try? file?.bindableArtboard(withName: name) {
if let artboard = instance?.artboardProperty(fromPath: "board") {
artboard.setValue(obj)
rive?.play()
bool.toggle()
}
}
} label: {
Text("Change artboard")
}event_-_ui.revScreen Recording 2025-08-21 at 23.36.20.mov