Skip to content

[framework] Animatable.fromCallback and code snippet#108661

Merged
auto-submit[bot] merged 8 commits intoflutter:masterfrom
jonahwilliams:converting
Aug 9, 2022
Merged

[framework] Animatable.fromCallback and code snippet#108661
auto-submit[bot] merged 8 commits intoflutter:masterfrom
jonahwilliams:converting

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Jul 30, 2022

Add an easy way to transform an animation using a callback

@flutter-dashboard flutter-dashboard bot added a: animation Animation APIs framework flutter/packages/flutter repository. See also f: labels. labels Jul 30, 2022
@jonahwilliams
Copy link
Contributor Author

@goderbauer I'd like to redeem my points :smile . I noticed another pattern I was unable to replace with the transform argument of fromValueListenable, since there is no good way to change the type unless the transform argument is required. Tween doesn't really work, because the animation doesn't really have a defined curve or end/start

Copy link
Member

Choose a reason for hiding this comment

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

Could use AnimationWithParentMixin?

Copy link
Member

Choose a reason for hiding this comment

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

In theory, you can achieve the same thing by implementing a custom Animatable class (only have to implement the transform method with the closure you would provide here) and then use Animation.drive.

This API avoids the extra class definition, I guess. Is that really such a hassle?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, and I guess Animation.drive only works if the parent is a Animation<double>. This one in theory allows any Animation to be transformed into any other... Is that a feature you need?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh maybe, let me look into that more.

@jonahwilliams
Copy link
Contributor Author

Drive solves this problem. Perhaps I should re-tool this PR into an additional of how to use Animation.drive?

@goderbauer
Copy link
Member

Drive solves this problem. Perhaps I should re-tool this PR into an additional of how to use Animation.drive?

That would be much appreciated!

@jonahwilliams jonahwilliams changed the title [framework] Animation.map [framework] Animatable.fromCallback and code snippet Aug 7, 2022
///
/// * [Animation.drive], which provides an example for how this can be
/// used.
const factory Animatable.fromCallback(AnimatableCallback<T> callback) = _CallbackAnimatable<T>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a little bit more API. It felt a bit silly to create a class just to wrap a callback in the sample code

@jonahwilliams jonahwilliams marked this pull request as ready for review August 7, 2022 00:48
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

/// * [CurvedAnimation], an alternative to [CurveTween] for applying easing
/// curves, which supports distinct curves in the forward direction and the
/// reverse direction.
/// * [Animatable.fromCallback], which allows creating an animatable from an
Copy link
Member

Choose a reason for hiding this comment

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

nit: animatable -> Animatable (or [Animatable])?

/// }));
/// ```
///
/// {@end-tool}
Copy link
Member

Choose a reason for hiding this comment

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

Nice doc!

// late Animation<Offset> _animation;
// late AnimationController _controller;

/// A typedef used to create an [Animatable] from a callback.
Copy link
Member

Choose a reason for hiding this comment

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

nit: As per style guide link this doc directly to its use by including [Animatable.fromCallback] in the doc comment.

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 9, 2022
@auto-submit auto-submit bot merged commit 8f0981c into flutter:master Aug 9, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 10, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Aug 10, 2022
camsim99 pushed a commit to camsim99/flutter that referenced this pull request Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: animation Animation APIs autosubmit Merge PR when tree becomes green via auto submit App framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants