Skip to content

Conversation

@flschweiger
Copy link
Contributor

@flschweiger flschweiger commented Dec 8, 2018

This PR adds a reverse flag to the repeat() method of the AnimationController. With that feature it will be easier to create 'yoyo' animations like a glowing Flutter logo:

AnimationController(vsync: this, duration: Duration(seconds: 1))..repeat(reverse: true);

Also have a look at the following Stackoverflow question: https://stackoverflow.com/questions/49604221/how-to-do-yoyo-animation-in-flutter

So right now it's only possible to achieve this by listening to the current status of the AnimationController and alternating between calling forward() and reverse() or through combining a fade-in animation with a fade-out animation.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@flschweiger
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@zoechi zoechi added framework flutter/packages/flutter repository. See also f: labels. a: animation Animation APIs labels Dec 9, 2018
@goderbauer
Copy link
Member

@HansMuller Can you review this?

@HansMuller
Copy link
Contributor

@goderbauer Looks like a nice enhancement. Will review this week.

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is pretty close to the finish line! Just a few more tweaks, mostly for the corner cases.

@flschweiger
Copy link
Contributor Author

@HansMuller Reworked the PR again with a nicer implementation of the repeating mechanism. Would be cool if you could have a look 😃

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

If you could add just one last comment to the test, I can land this for you.

This is a nice new animation feature. Thanks for the contribution and thanks for hanging in there!

expect(controller.value, 0.0);

controller.repeat(reverse: true);
tick(const Duration(milliseconds: 0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear why this first duration=0 tick is always needed. I assume it's to enable the simulation to figure out which way it's going. Might be helpful to include one comment at the beginning here, to explain what's going on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be found in other tests (e.g. test('animateTo sets correct status') or test('after a reverse call animateTo sets correct status'). Every time when starting a new simulation, the first tick is used to initialise the simulation inside the AnimationController. When the line is removed, the elapsed time will always be 0 which means that the simulation will be evaluated at the time 0 and not after x milliseconds.

In the end I didn't comment on that because it is used quite often in the other tests already 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, OK.

@HansMuller HansMuller merged commit d1bde2e into flutter:master Jan 24, 2019
kangwang1988 pushed a commit to XianyuTech/flutter that referenced this pull request Feb 12, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: animation Animation APIs framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants