-
Notifications
You must be signed in to change notification settings - Fork 29.1k
SpringDescription parameter for the AnimationController fling method #65057
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
SpringDescription parameter for the AnimationController fling method #65057
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
I'm still not sure why |
@LongCatIsLooong refer to my comment here #60419 (comment). See where I want to use this. When I have such animation, I want to have all the valid animation statuses: forward, complete, reverse, dismissed. Using Fling is working fine and updates status properly, so I can track if my bottom page is now expanding or whether it is collapsing. |
@nt4f04uNd that makes sense. Thanks for the explanation! In that case the documentation needs to be updated, as the custom spring is not guaranteed to be critically damped. Also I think the interaction between underdamped/overdamped springs with |
@nt4f04uNd Do you have plans to follow up on the feedback soon-ish? |
@LongCatIsLooong @goderbauer sorry for delayed updates. I updated docs a bit, but I guess I'm not competent enough to document the relationships between various types of springs and I tested with different bounds and different types of springs, and I'm not that much into all that stuff, so if you think it should be documented more detailed, I ask you to do that instead of me |
@nt4f04uNd yeah it gets a bit hairy when the given spring has a damping ratio that's not 1. Does your use case involve using a non-critically damped spring? If not I think we can add an assert to ensure the custom |
@LongCatIsLooong over damped seems to be working pretty ok and I use it as I want to slow down a bit the default critically damped spring and make it a bit smoother (I use the one I included in tests). Did you observe any problems with over damped springs? Because I experience problems only with under damped as I said and if we want to add asserts, I would do that allowing to use both critically and over damped springs. If you can't test it out, I can upload some videos of how fling with various springs looks like |
I think the problem with using an overdamped |
@LongCatIsLooong that's not the case. If you set ratio to very large number, the animation will always end up in the upper/lower bound (depending on the direction), but what you actually will see when you do this - is drastically slowed down movement, it's not stopped. You can set But I think maybe we should actually document in this method the behaviour of different spring types to not confuse anyone who will actually try to do that. |
@LongCatIsLooong also, just to be sure, as with large ratio the animation may start moving just because of applying dilation (I'm not aware how it internally works), so I added listener to the controller and it reports about changes even without dilation, even though on the screen there's no animation at all |
Oh you're right, it should eventually converge to 0: flutter/packages/flutter/lib/src/physics/spring_simulation.dart Lines 232 to 235 in 1510865
Sounds good 👍 |
@LongCatIsLooong will we restrict |
It looks like we clamp the flutter/packages/flutter/lib/src/animation/animation_controller.dart Lines 785 to 798 in 1510865
I don't know if there's a use case for that, the movement doesn't feel natural (as the animation suddenly stops when it goes out of range, losing all its momentum, then regains the momentum after a short while). But I'm OK with just documenting the behavior and warning developers about the weirdness. @goderbauer do you think we should disallow underdamped springs in this case? |
(PR triage): @LongCatIsLooong @nt4f04uNd are there still plans for this PR? |
@goderbauer I've been planning to add a few comment lines about how the springs work with fling, but been waiting for your response
|
I think we should disallow it if it doesn't make sense and from the discussion so far it sounds like it wouldn't really make sense? We can always revisit that if we have a use case that requires it. |
@goderbauer @LongCatIsLooong I guess that's it |
Thanks! There seems to be a merge conflict, could you resolve it? |
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR! LGTM.
@nt4f04uNd could you do a |
@LongCatIsLooong do you mean |
@nt4f04uNd yes. The linux docs check on CI seems to be failing for some unrelated reason so let's see if syncing to head fixes that. |
Description
I provided the fling method with a new parameter
springDescription
. It just adds more customization to the methon by allowing to override the existing internal constant variable and so permitting developers to manipulate how the resulting fling animation will look like.Related Issues
#64400 - the original issue, though I then decided that tolerance shouldn't be public.
Tests
Added
Checklist
Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change