question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

rive not change animation

See original GitHub issue

Hey, I try to do a dark mode vs light mode animation

it the same animation with different color

I try to replace the RIV file on state change but the canvas does not update and I see the old animation. then I try to do in the Riv File 2 different animation with do name and change the animation

const params = {
    src: RiveAnimation,
    autoplay: true,
    animations: isDark ? "dark" : "light", // this is not working 
};

const { RiveComponent, rive } = useRive(params);

useEffect(() => {
    if (rive) {
      if (isDark) {
        console.log("dark");
        rive.stop("light");
        rive.play("dark");
      } else {
        rive.stop("dark");
        rive.play("light");
      }
      console.log(rive.playingAnimationNames);
    }
  }, [isDark, rive]);

and the animation does not update as well

any idea how to fix this?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

3reactions
gzabancommented, Jun 29, 2021

Thanks a lot for the quick answer and for this plugin - The solution works great, I also understood the problem with my animation.

1reaction
aviviancommented, Jun 29, 2021

@gzaban Had a look into this. The easiest fix is to call reset() in between stopping and playing an animation.

rive.stop();
rive.reset();
rive.play("dark");

From looking at the file, it looks like your light animation overwrites the fill, but the dark animation doesn’t (since it’s already set on the design). This is why changing from dark to light works but not light to dark. When you stop an animation, any changes made to the artboard by previous animations persist and aren’t undone unless you call reset. E.g Let say I have a circle who’s animation changed it’s size bigger and smaller in a loop, if I stopped the animation while it was big, the circle would remain big. That’s essentially what’s happening here. Your light animation sets the fill on the hat and chest but the dark animation doesn’t. So you could fix the file such that the dark animation also sets the fill, but calling reset() works fine here as well 😃.

Another idea is to have a state machine for this file, with a toggle input between light and dark. Again not necessary, but could be worth exploring.

Read more comments on GitHub >

github_iconTop Results From Across the Web

New Animation Edit not showing up in Rive File#520 - Sign in
Added animated text, which shows up when in Animation mode and when rendered to Cloud Renderer. However, the file is missing the animation...
Read more >
Flutter Rive - animation doesn't change when ... - Stack Overflow
I tried to play with boolean input and it worked really nice, but changing number input won't change the animation at all.
Read more >
How do I change between animation names? #26 - GitHub
The class 'RiveFile' doesn't have an unnamed constructor. Try using one of the named constructors defined in 'RiveFile'. and the line if (file....
Read more >
Runtime - Rive Feedback
As I understand we can change animation only if it is provided by animation itse ... Hi, may be is crazy:) do you...
Read more >
rive | Flutter Package - Pub.dev
RiveAnimation now takes lists of animation and state machine names and plays ... Fixing an issue with StateMachine changes not being applied on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found