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

Tween hooks #39

Open
rrousselGit opened this issue Jan 25, 2019 · 4 comments
Open

Tween hooks #39

rrousselGit opened this issue Jan 25, 2019 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@rrousselGit
Copy link
Owner

Flutter offer multiple Tween classes.

A common use-case it to use them to tween between a previous and new value through didUpdateWidget.

Through hooks, this can be automated into a useTween:

final counter = useState(0);
final Tween tween = useTween(counter.value);
@rrousselGit rrousselGit self-assigned this Jan 25, 2019
@rrousselGit rrousselGit added the enhancement New feature or request label Jan 30, 2019
@sahandevs
Copy link
Contributor

something like this? :

V useTween<T extends Tween<V>, V extends dynamic>(
  V value, {
  @required T Function(V begin, V end) builder,
  Duration duration,
  double progress,
}) {
  assert(builder != null);
  assert(progress != null && duration != null);
  assert(progress == null && duration == null);
  assert(progress != null && (progress > 1.0 || progress < 1.0));

}

usage :

final color = useTween(Colors.red.shade400,
  builder: (begin, end) => ColorTween(begin: begin, end: end),
  progress: 0.5
);

@rrousselGit
Copy link
Owner Author

Flutter now has TweenAnimationBuilder so that hook is not very important.

Although if we want to make such hook, it'd be logical to use the same API as TweenAnimationBuilder:

final value = useTween(IntTween(end: 42), duration: const Duration(seconds: 2));

@timcreatedit
Copy link
Contributor

We have hooks like this in rivership. They are insanely practical, and this is our implementation.

It's partly opinionated and wouldn't be feasible to move over here like this, but I could raise a PR with a similar implementation if you think these hooks are a fit?

@rrousselGit
Copy link
Owner Author

Sure that'd be valuable!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants