Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

triggerInput fires before riveView initialization by .view(), failing to reflect the triggered state #338

Open
daikinetic opened this issue Sep 12, 2024 · 4 comments

Comments

@daikinetic
Copy link

daikinetic commented Sep 12, 2024

Description

When attempting to call riveViewModel.triggerInput before riveViewModel.view() initializes riveViewModel.riveView, the desired animation state is not reflected correctly in the view after initialization.

More specifically, the target triggerInput is triggerInput(“isActive”).
This is done by calling a function setDefaultState in init. We call the function in init to easily reproduce events, but in our actual project, we call them from the outside.

It is possible that our stateMachine is not created in the right way.

Provide a Repro

  1. Please clone my fork and checkout triggerIssue branch.
git clone https://github.com/daikinetic/rive-ios.git
git checkout triggerIssue
  1. Open and run Example-iOS Project
Example-iOS/RiveExample.xcodeproj
  1. I created a file ReproViewController.swift and added it to the preview app table item for you to review.

Source .riv/.rev file

Included in the forked repository. favorite_animation.riv

Expected behavior

Even if riveViewModel.triggerInput(“isActive”) is called before riveViewModel.view(), I want the view after initialization to correctly reflect riveViewModel.triggerInput(“isActive”) animation state (favorite button is active) correctly.

Screenshots

It refers to the state that the screen already looks like this image when it is opened.

スクリーンショット 2024-09-12 18 24 57

Device & Versions (please complete the following information)

  • Device: iOS Simulator, iPhone 15 Pro
  • iOS version: iOS 17.4

Additional context

The state machine in this .riv file looks like the following capture. I may be wrong about how to create this state machine, in which case please point this out to me.

スクリーンショット 2024-09-12 18 24 57
@daikinetic daikinetic mentioned this issue Sep 12, 2024
@muukii
Copy link

muukii commented Sep 13, 2024

This is the following comment
RiveView does not display the latest state updated by the triggerInput method before displaying in view.

let riveView = self.riveViewModel.createRiveView()
view.addSubview(riveView)
self.riveViewModel.triggerInput("isActive")
riveView.frame = .init(origin: view.center, size: .init(width: 50, height: 50)) 

It seems that RiveView requires a first-time render to get ready to accept triggerInput.

@muukii
Copy link

muukii commented Sep 15, 2024

I ran this code before triggerInput, which worked for this case.

riveViewModel.riveModel?.stateMachine?.advance(by: 0)

@dskuza
Copy link
Collaborator

dskuza commented Sep 18, 2024

@muukii Thanks for sharing, we're looking into this!

@cerupcat
Copy link

Is there a way to set initial state on startup? I'm also seeing similar issues where if I set certain text runs or triggers prior to Rive being fully initialized it says in the initial state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants