rive-app / rive-ios

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

Loop setting with Rive Editor cannot be overridden by code #291

Closed kenjitayama closed 4 months ago

kenjitayama commented 4 months ago

Description

Loop setting with Rive Editor cannot be overridden by code. Specifically, loop specified with riveViewModel.play(loop:) is not respected. I experienced this with .riv file converted from Lottie json file. I haven't made any original .riv files yet. I am on a free plan, so I can't see existing .riv which don't reproduce this issue with Rive Editor.

Provide a Repro

  1. Please clone my fork and checkout loopIssue branch.

    git clone https://github.com/kenjitayama/rive-ios.git
    git checkout loopIssue
  2. Open and run Demo-App Project

    Demo-App/RiveExampleSPM.xcodeproj
  3. SplashScreen.swift is modified and Switch.riv (converted from Switch.json) is displayed instead of windy_tree.riv

    Conversion from Lottie was done with Rive Editor 0.8.1039

Source .riv/.rev file

Included in the forked repository.

Expected behavior

Please press play/pause button twice. This triggers the code tree.play(loop: .oneShot).

Looks like the loop setting with Rive Editor cannot be overridden by code. The opposite happens too (One Shot setting in .riv file cannot be overridden with loop: .loop). This does not happen when using the original .riv file (windy_tree.riv).

By the way, when app launches the button is displayed as "play" but should be "pause" (nothing to do with this issue, but noting because it might be confusing)

Screenshots

Device & Versions (please complete the following information)

Additional context

HayesGordon commented 4 months ago

Hi @kenjitayama, I had a quick look. Note when you call play and not provide any information on the artboard/state-machine/animation to play, then it will use the defaults set in the editor, not finding that it will play the first state machine, not finding that it will play the first animation.

I suspect it's playing the state machine, and note that these looping conditions are for animation timelines, not the state machine (the state machine will respect the conditions defined in the editor).

Within the state-machine in the Rive editor you can configure these conditions (looping, animation mixing, etc).

To fix this particular problem, when initializing the viewmodel you need to specify the animation you want to play: var tree = RiveViewModel(fileName: "Switch", animationName: "yourAnimationName")

But playing a singular animation is a small subset of Rive's features, and you're much better off playing a State Machine instead.

I also recommend you run the example app (instructions: https://help.rive.app/runtimes/overview/ios#example-app) instead of the demo app, as it has more examples and showcases the state machine better. We should remove/update this demo app.

You can find docs on the state machine here:

I am going to close this issue, but if you think there is something I missed with regard to the issue, please reopen it.

kenjitayama commented 4 months ago

Thank you for explaining in detail.

I suspect it's playing the state machine, and note that these looping conditions are for animation timelines, not the state machine (the state machine will respect the conditions defined in the editor).

This perfectly explains whats happening. Yes, I have just one state machine and no animation timelines in my editor. Now I see why looping conditions set in code is not working.

Thank you for the additional information too!

aj-cooler commented 3 months ago

Wow, this has to be in the docs! https://help.rive.app/runtimes/playback