rive-app / rive-ios

iOS runtime for Rive
MIT License
468 stars 53 forks source link

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

Closed pschuster closed 1 year ago

pschuster commented 1 year ago

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.

duncandoit commented 1 year ago

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)
mjtalbot commented 1 year ago

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.

m-yeroshenko commented 4 months ago

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

HayesGordon commented 4 months ago

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

m-yeroshenko commented 4 months ago

Hi! Happy Friday! Thank you for your answer! Will look into the Events docs.

On 1 Mar 2024, at 16:34, Gordon @.***> wrote:

Hi @m-yeroshenko https://github.com/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

— Reply to this email directly, view it on GitHub https://github.com/rive-app/rive-ios/issues/237#issuecomment-1973310716, or unsubscribe https://github.com/notifications/unsubscribe-auth/BBP2IY26RKP2SHYUCPTCN6LYWCGXJAVCNFSM6AAAAAAS2GUFO2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZTGMYTANZRGY. You are receiving this because you were mentioned.