Skip to content

Data binding - Triggers not advancing state machine unless clicked on or forced to loop #383

@lbg-jackmcgrory

Description

@lbg-jackmcgrory

Description

I have set up a view model which contains triggers for an animation that I have simplified for this example. For some reason if I call one of the triggers from the view model the animation will not progress if it is in a settled state despite the fact if it was a normal input trigger it would work as expected.

You can see this in the attached video as you can only make the animation progress after the trigger has been called if you either click on the animation, add an infinite repeating loop to the rive file or the better solution suggested on the Rive support forums - to call riveView.play() after calling the trigger.

I have tested the file in the editor and React and the triggers do fire inside the view model as expected so not sure if this is a bug on iOS or not.

Provide a Repro

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
        }
        
    }
}

Source .riv/.rev file

Rev File - Simple Circle

Simplified rive file for this example with a circle that has view model with two triggers one to move it up and one to move it down

Expected behaviour

Would expect when the trigger is called, the animations state machine progresses if there is a transition that is dependant on that trigger firing

Screenshots

ios.mov

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions