rive-app/rive-ios

StateMachineDelegate receivedInput never called - how I am supposed to listen on events in Rive in my iOS App?

Closed this issue · 5 comments

Description

I have implemented a simple UI in Rive with buttons. I have implemented Press Up Listeners and added the buttons as targets. When the button is pressed, a trigger input is activated playing an animation. So far, so good. But what I want to do is to handle the button press in the "surrounding" iOS App. So, my expectation is, that if the user taps on a button in the rive window, something happens in my App. In my case, a popup window should be opened (like a settings button).

I expected to use the stateMachineDelegate and implement the receivedInput function:

    func stateMachine(_ stateMachine: RiveStateMachineInstance, receivedInput input: StateMachineInput) {
        print(input);
    }

However, this function is never called. The other delegate function didChangeState works fine, so the delegate is set and working. Digging trough the code, I didn't find a place where receivedInput is being called anywhere, so it seems to be just a stub or so.

If that is the case, how I am supposed to listen on events/input changes in the Rive animation to handle them in my App.

For your use-case these delegate functions should work:

    @objc optional func touchBegan(onArtboard artboard: RiveArtboard?, atLocation location: CGPoint)
    @objc optional func touchMoved(onArtboard artboard: RiveArtboard?, atLocation location: CGPoint)
    @objc optional func touchEnded(onArtboard artboard: RiveArtboard?, atLocation location: CGPoint)
    @objc optional func touchCancelled(onArtboard artboard: RiveArtboard?, atLocation location: CGPoint)

Hi @pschuster were you able to confirm that the delegates work for you?

You should be able to listen for state changes & touch events. I am assuming in this case didChangeState is not giving you enough to trigger your callback at the right moment?

It does indeed look like "receivedInput" is not actually hooked up to anything at this point, I'm going to have a look to figure out where this receivedInput parameter is headed, I'm not sure it's a good match for your use case, but of course we do not have a clear set of outgoing "events" available in the runtime yet.

Typically we would expect inputs to be set by apps & of course touch events now, but their main consumer is intended to be the state machine that they are inputs for. You should be able to change a state based on the trigger, which in turn would let you wire up your callback to the "didChangeState" delegate.

Hi, @mjtalbot!
Could you tell, please, if receivedInput is supposed to be working now in the latest iOS SDK version of 5.9.1?
I'm running into the same issue where I need to detect the user's exact input on the Rive animation.
Appreciate your answer

Hi @m-yeroshenko , this receivedInput delegate is something I believe should not be exposed, and is either a left over API, or a misnomer for the intended behaviour.

Please note that we launched Rive Events a few months back. Events are the correct way to communicate important information to runtime from your animation, and it is what you probably want to use (instead of something like receiveInput)

Please see the event documentation here: https://help.rive.app/runtimes/rive-events