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

How can one-way animation looping be implemented? #956

Closed
gtolarc opened this issue Apr 9, 2020 · 6 comments
Closed

How can one-way animation looping be implemented? #956

gtolarc opened this issue Apr 9, 2020 · 6 comments
Milestone

Comments

@gtolarc
Copy link

gtolarc commented Apr 9, 2020

Here is my sample code. If loop is implemented as the following, 1-> 10, 10-> 1, 1-> 10, ... are repeated. But I want to repeat 1-> 10, 1-> 10, 1-> 10. Is there any way?

const LED = props => {
  const [spring, set] = useSpring(() => ({
    from: { number: 1 },
    to: async next => {
      while (1) {
        await next({ number: 10 });
        await next({ number: 1 });
      }
    },
    config: {
      duration: 3000
    }
  }));

  return <a.div>{spring.number}</a.div>;
};
@aleclarson
Copy link
Contributor

In the latest canary, you can use the loop prop:

useSpring({
  loop: true,
  from: { n: 1 },
  to: { n: 10 },
})

Note: I have some bug fixes for the loop prop ready for the next canary, so bugs might exist in the latest canary that prevent the example above from working as expected.

@gtolarc
Copy link
Author

gtolarc commented Apr 9, 2020

Thank you and look forward to the next release :)

@gtolarc gtolarc closed this as completed Apr 9, 2020
@aleclarson aleclarson added this to the v9.0.0 milestone Apr 9, 2020
@aleclarson
Copy link
Contributor

Now available in v9.0.0-rc.2 #985

@shubhamkes
Copy link

shubhamkes commented Aug 31, 2020

u can do so in v8 as well by reset flag

useSpring({
    reset: true,
    from: { n: 1 },
    to: { n: 10 },
})

@aleclarson
Copy link
Contributor

@shubhamkes Sort of. That requires you to rerender for each repetition.

@shubhamkes
Copy link

oh is it? thought they are same. is v9.0.0-rc.2 recommended for prod?

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

3 participants