Commit 99c0edd6 authored by Matt Perry's avatar Matt Perry

Rename some animation classes.

* Intentions => Behaviors
* SlideIn => SlideTransition
* FadeIn => FadeTransition
* removed unused AnimatedContainer intentions
parent dc9a4ccd
...@@ -71,6 +71,11 @@ class AnimatedMatrix4Value extends AnimatedValue<Matrix4> { ...@@ -71,6 +71,11 @@ class AnimatedMatrix4Value extends AnimatedValue<Matrix4> {
} }
} }
abstract class AnimationBehavior {
void initFields(AnimatedContainer original);
void syncFields(AnimatedContainer original, AnimatedContainer updated);
}
class ImplicitlyAnimatedValue<T> { class ImplicitlyAnimatedValue<T> {
final AnimationPerformance performance = new AnimationPerformance(); final AnimationPerformance performance = new AnimationPerformance();
final AnimatedValue<T> _variable; final AnimatedValue<T> _variable;
...@@ -93,13 +98,8 @@ class ImplicitlyAnimatedValue<T> { ...@@ -93,13 +98,8 @@ class ImplicitlyAnimatedValue<T> {
} }
} }
abstract class AnimationIntention { abstract class ImplicitlyAnimatedFieldBehavior<T> extends AnimationBehavior {
void initFields(AnimatedContainer original); ImplicitlyAnimatedFieldBehavior(this.duration);
void syncFields(AnimatedContainer original, AnimatedContainer updated);
}
abstract class ImplicitlySyncFieldIntention<T> extends AnimationIntention {
ImplicitlySyncFieldIntention(this.duration);
Duration duration; Duration duration;
ImplicitlyAnimatedValue<T> field; ImplicitlyAnimatedValue<T> field;
...@@ -131,71 +131,71 @@ abstract class ImplicitlySyncFieldIntention<T> extends AnimationIntention { ...@@ -131,71 +131,71 @@ abstract class ImplicitlySyncFieldIntention<T> extends AnimationIntention {
} }
} }
class ImplicitlySyncConstraintsIntention extends ImplicitlySyncFieldIntention<BoxConstraints> { class ImplicitlyAnimatedConstraintsBehavior extends ImplicitlyAnimatedFieldBehavior<BoxConstraints> {
ImplicitlySyncConstraintsIntention(Duration duration) : super(duration); ImplicitlyAnimatedConstraintsBehavior(Duration duration) : super(duration);
BoxConstraints getter(AnimatedContainer container) => container.constraints; BoxConstraints getter(AnimatedContainer container) => container.constraints;
void setter(AnimatedContainer container, BoxConstraints val) { container.constraints = val; } void setter(AnimatedContainer container, BoxConstraints val) { container.constraints = val; }
AnimatedValue initField(BoxConstraints val) => new AnimatedBoxConstraintsValue(val); AnimatedValue initField(BoxConstraints val) => new AnimatedBoxConstraintsValue(val);
} }
class ImplicitlySyncDecorationIntention extends ImplicitlySyncFieldIntention<BoxDecoration> { class ImplicitlyAnimatedDecorationBehavior extends ImplicitlyAnimatedFieldBehavior<BoxDecoration> {
ImplicitlySyncDecorationIntention(Duration duration) : super(duration); ImplicitlyAnimatedDecorationBehavior(Duration duration) : super(duration);
BoxDecoration getter(AnimatedContainer container) => container.decoration; BoxDecoration getter(AnimatedContainer container) => container.decoration;
void setter(AnimatedContainer container, BoxDecoration val) { container.decoration = val; } void setter(AnimatedContainer container, BoxDecoration val) { container.decoration = val; }
AnimatedValue initField(BoxDecoration val) => new AnimatedBoxDecorationValue(val); AnimatedValue initField(BoxDecoration val) => new AnimatedBoxDecorationValue(val);
} }
class ImplicitlySyncMarginIntention extends ImplicitlySyncFieldIntention<EdgeDims> { class ImplicitlyAnimatedMarginBehavior extends ImplicitlyAnimatedFieldBehavior<EdgeDims> {
ImplicitlySyncMarginIntention(Duration duration) : super(duration); ImplicitlyAnimatedMarginBehavior(Duration duration) : super(duration);
EdgeDims getter(AnimatedContainer container) => container.margin; EdgeDims getter(AnimatedContainer container) => container.margin;
void setter(AnimatedContainer container, EdgeDims val) { container.margin = val; } void setter(AnimatedContainer container, EdgeDims val) { container.margin = val; }
AnimatedValue initField(EdgeDims val) => new AnimatedEdgeDimsValue(val); AnimatedValue initField(EdgeDims val) => new AnimatedEdgeDimsValue(val);
} }
class ImplicitlySyncPaddingIntention extends ImplicitlySyncFieldIntention<EdgeDims> { class ImplicitlyAnimatedPaddingBehavior extends ImplicitlyAnimatedFieldBehavior<EdgeDims> {
ImplicitlySyncPaddingIntention(Duration duration) : super(duration); ImplicitlyAnimatedPaddingBehavior(Duration duration) : super(duration);
EdgeDims getter(AnimatedContainer container) => container.padding; EdgeDims getter(AnimatedContainer container) => container.padding;
void setter(AnimatedContainer container, EdgeDims val) { container.padding = val; } void setter(AnimatedContainer container, EdgeDims val) { container.padding = val; }
AnimatedValue initField(EdgeDims val) => new AnimatedEdgeDimsValue(val); AnimatedValue initField(EdgeDims val) => new AnimatedEdgeDimsValue(val);
} }
class ImplicitlySyncTransformIntention extends ImplicitlySyncFieldIntention<Matrix4> { class ImplicitlyAnimatedTransformBehavior extends ImplicitlyAnimatedFieldBehavior<Matrix4> {
ImplicitlySyncTransformIntention(Duration duration) : super(duration); ImplicitlyAnimatedTransformBehavior(Duration duration) : super(duration);
Matrix4 getter(AnimatedContainer container) => container.transform; Matrix4 getter(AnimatedContainer container) => container.transform;
void setter(AnimatedContainer container, Matrix4 val) { container.transform = val; } void setter(AnimatedContainer container, Matrix4 val) { container.transform = val; }
AnimatedValue initField(Matrix4 val) => new AnimatedMatrix4Value(val); AnimatedValue initField(Matrix4 val) => new AnimatedMatrix4Value(val);
} }
class ImplicitlySyncWidthIntention extends ImplicitlySyncFieldIntention<double> { class ImplicitlyAnimatedWidthBehavior extends ImplicitlyAnimatedFieldBehavior<double> {
ImplicitlySyncWidthIntention(Duration duration) : super(duration); ImplicitlyAnimatedWidthBehavior(Duration duration) : super(duration);
double getter(AnimatedContainer container) => container.width; double getter(AnimatedContainer container) => container.width;
void setter(AnimatedContainer container, double val) { container.width = val; } void setter(AnimatedContainer container, double val) { container.width = val; }
AnimatedValue initField(double val) => new AnimatedValue<double>(val); AnimatedValue initField(double val) => new AnimatedValue<double>(val);
} }
class ImplicitlySyncHeightIntention extends ImplicitlySyncFieldIntention<double> { class ImplicitlyAnimatedHeightBehavior extends ImplicitlyAnimatedFieldBehavior<double> {
ImplicitlySyncHeightIntention(Duration duration) : super(duration); ImplicitlyAnimatedHeightBehavior(Duration duration) : super(duration);
double getter(AnimatedContainer container) => container.height; double getter(AnimatedContainer container) => container.height;
void setter(AnimatedContainer container, double val) { container.height = val; } void setter(AnimatedContainer container, double val) { container.height = val; }
AnimatedValue initField(double val) => new AnimatedValue<double>(val); AnimatedValue initField(double val) => new AnimatedValue<double>(val);
} }
List<AnimationIntention> implicitlySyncFieldsIntention(Duration duration) { List<AnimationBehavior> implicitlyAnimate(Duration duration) {
return [ return [
new ImplicitlySyncConstraintsIntention(duration), new ImplicitlyAnimatedConstraintsBehavior(duration),
new ImplicitlySyncDecorationIntention(duration), new ImplicitlyAnimatedDecorationBehavior(duration),
new ImplicitlySyncMarginIntention(duration), new ImplicitlyAnimatedMarginBehavior(duration),
new ImplicitlySyncPaddingIntention(duration), new ImplicitlyAnimatedPaddingBehavior(duration),
new ImplicitlySyncTransformIntention(duration), new ImplicitlyAnimatedTransformBehavior(duration),
new ImplicitlySyncWidthIntention(duration), new ImplicitlyAnimatedWidthBehavior(duration),
new ImplicitlySyncHeightIntention(duration) new ImplicitlyAnimatedHeightBehavior(duration)
]; ];
} }
...@@ -203,8 +203,7 @@ class AnimatedContainer extends AnimatedComponent { ...@@ -203,8 +203,7 @@ class AnimatedContainer extends AnimatedComponent {
AnimatedContainer({ AnimatedContainer({
Key key, Key key,
this.child, this.child,
this.intentions, this.behavior,
this.tag,
this.constraints, this.constraints,
this.decoration, this.decoration,
this.width, this.width,
...@@ -223,17 +222,16 @@ class AnimatedContainer extends AnimatedComponent { ...@@ -223,17 +222,16 @@ class AnimatedContainer extends AnimatedComponent {
double width; double width;
double height; double height;
List<AnimationIntention> intentions; List<AnimationBehavior> behavior;
dynamic tag; // Used by intentions to determine desired state.
void initState() { void initState() {
for (AnimationIntention i in intentions) for (AnimationBehavior i in behavior)
i.initFields(this); i.initFields(this);
} }
void syncFields(AnimatedContainer updated) { void syncFields(AnimatedContainer updated) {
child = updated.child; child = updated.child;
for (AnimationIntention i in intentions) for (AnimationBehavior i in behavior)
i.syncFields(this, updated); i.syncFields(this, updated);
} }
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file contains a set of common intentions to use with AnimationContainer
// for describing how to animate certain properties.
import 'dart:sky';
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart';
import 'package:sky/widgets/animated_container.dart';
import 'package:sky/widgets/basic.dart';
import 'package:vector_math/vector_math.dart';
// Slides a container in from |start| to |end| when the container's |tag| is
// true (reverses if false).
class SlideInIntention extends AnimationIntention {
SlideInIntention({Duration duration, this.performance, Point start, Point end}) {
if (performance == null) {
assert(duration != null);
performance = new AnimationPerformance(duration: duration);
}
_position = new AnimatedValue<Point>(start, end: end);
performance.addVariable(_position);
}
AnimatedValue<Point> _position;
AnimationPerformance performance;
void initFields(AnimatedContainer container) {
performance.addListener(() { _updateProgress(container); });
performance.progress = 0.0;
if (container.tag)
performance.play();
}
void syncFields(AnimatedContainer original, AnimatedContainer updated) {
if (original.tag != updated.tag) {
original.tag = updated.tag;
performance.play(original.tag ? Direction.forward : Direction.reverse);
}
}
void _updateProgress(AnimatedContainer container) {
container.setState(() {
container.transform = new Matrix4.identity()
..translate(_position.value.x, _position.value.y);
});
}
}
// Changes color from |start| to |end| when the container's |tag| is true
// (reverses if false).
class ColorTransitionIntention extends AnimationIntention {
ColorTransitionIntention({Duration duration, this.performance, Color start, Color end}) {
if (performance == null) {
assert(duration != null);
performance = new AnimationPerformance(duration: duration);
}
_color = new AnimatedColorValue(start, end: end);
performance.addVariable(_color);
}
AnimatedColorValue _color;
AnimationPerformance performance;
void initFields(AnimatedContainer container) {
performance.addListener(() { _updateProgress(container); });
performance.progress = 0.0;
if (container.tag)
performance.play();
}
void syncFields(AnimatedContainer original, AnimatedContainer updated) {
if (original.tag != updated.tag) {
original.tag = updated.tag;
performance.play(original.tag ? Direction.forward : Direction.reverse);
}
}
void _updateProgress(AnimatedContainer container) {
container.setState(() {
container.decoration = new BoxDecoration(backgroundColor: _color.value);
});
}
}
...@@ -175,10 +175,10 @@ class Dismissable extends StatefulComponent { ...@@ -175,10 +175,10 @@ class Dismissable extends StatefulComponent {
onGestureFlingStart: _handleFlingStart, onGestureFlingStart: _handleFlingStart,
child: new SizeObserver( child: new SizeObserver(
callback: _handleSizeChanged, callback: _handleSizeChanged,
child: new SlideIn( child: new SlideTransition(
performance: _fadePerformance, performance: _fadePerformance,
position: new AnimatedValue<Point>(Point.origin, end: _activeCardDragEndPoint), position: new AnimatedValue<Point>(Point.origin, end: _activeCardDragEndPoint),
child: new FadeIn( child: new FadeTransition(
performance: _fadePerformance, performance: _fadePerformance,
onCompleted: _handleFadeCompleted, onCompleted: _handleFadeCompleted,
opacity: new AnimatedValue<double>(1.0, end: 0.0), opacity: new AnimatedValue<double>(1.0, end: 0.0),
......
...@@ -94,13 +94,13 @@ class Drawer extends StatefulComponent { ...@@ -94,13 +94,13 @@ class Drawer extends StatefulComponent {
onGestureTap: handleMaskTap onGestureTap: handleMaskTap
); );
Widget content = new SlideIn( Widget content = new SlideTransition(
performance: _performance, performance: _performance,
direction: showing ? Direction.forward : Direction.reverse, direction: showing ? Direction.forward : Direction.reverse,
position: new AnimatedValue<Point>(_kClosedPosition, end: _kOpenPosition), position: new AnimatedValue<Point>(_kClosedPosition, end: _kOpenPosition),
onDismissed: _onDismissed, onDismissed: _onDismissed,
child: new AnimatedContainer( child: new AnimatedContainer(
intentions: implicitlySyncFieldsIntention(const Duration(milliseconds: 200)), behavior: implicitlyAnimate(const Duration(milliseconds: 200)),
decoration: new BoxDecoration( decoration: new BoxDecoration(
backgroundColor: Theme.of(this).canvasColor, backgroundColor: Theme.of(this).canvasColor,
boxShadow: shadows[level]), boxShadow: shadows[level]),
......
...@@ -49,7 +49,7 @@ class Material extends Component { ...@@ -49,7 +49,7 @@ class Material extends Component {
Widget build() { Widget build() {
return new AnimatedContainer( return new AnimatedContainer(
intentions: implicitlySyncFieldsIntention(const Duration(milliseconds: 200)), behavior: implicitlyAnimate(const Duration(milliseconds: 200)),
decoration: new BoxDecoration( decoration: new BoxDecoration(
backgroundColor: _backgroundColor, backgroundColor: _backgroundColor,
borderRadius: edges[type], borderRadius: edges[type],
......
...@@ -89,11 +89,11 @@ class Transition extends TransitionBase { ...@@ -89,11 +89,11 @@ class Transition extends TransitionBase {
Widget build() { Widget build() {
// TODO(jackson): Hit testing should ignore transform // TODO(jackson): Hit testing should ignore transform
// TODO(jackson): Block input unless content is interactive // TODO(jackson): Block input unless content is interactive
return new SlideIn( return new SlideTransition(
performance: performance, performance: performance,
direction: direction, direction: direction,
position: new AnimatedValue<Point>(_kTransitionStartPoint, end: Point.origin, curve: easeOut), position: new AnimatedValue<Point>(_kTransitionStartPoint, end: Point.origin, curve: easeOut),
child: new FadeIn( child: new FadeTransition(
performance: performance, performance: performance,
direction: direction, direction: direction,
opacity: new AnimatedValue<double>(0.0, end: 1.0, curve: easeOut), opacity: new AnimatedValue<double>(0.0, end: 1.0, curve: easeOut),
......
...@@ -74,7 +74,7 @@ class SnackBar extends Component { ...@@ -74,7 +74,7 @@ class SnackBar extends Component {
) )
]..addAll(actions); ]..addAll(actions);
return new SlideIn( return new SlideTransition(
duration: _kSlideInDuration, duration: _kSlideInDuration,
direction: showing ? Direction.forward : Direction.reverse, direction: showing ? Direction.forward : Direction.reverse,
position: new AnimatedValue<Point>(const Point(0.0, 50.0), position: new AnimatedValue<Point>(const Point(0.0, 50.0),
......
...@@ -70,11 +70,10 @@ abstract class TransitionBase extends AnimatedComponent { ...@@ -70,11 +70,10 @@ abstract class TransitionBase extends AnimatedComponent {
Widget build(); Widget build();
} }
// TODO(mpcomplete): rename SlideTransition class SlideTransition extends TransitionBase {
class SlideIn extends TransitionBase {
// TODO(mpcomplete): this constructor is mostly boilerplate, passing values // TODO(mpcomplete): this constructor is mostly boilerplate, passing values
// to super. Is there a simpler way? // to super. Is there a simpler way?
SlideIn({ SlideTransition({
Key key, Key key,
this.position, this.position,
Duration duration, Duration duration,
...@@ -93,7 +92,7 @@ class SlideIn extends TransitionBase { ...@@ -93,7 +92,7 @@ class SlideIn extends TransitionBase {
AnimatedValue<Point> position; AnimatedValue<Point> position;
void syncFields(SlideIn updated) { void syncFields(SlideTransition updated) {
position = updated.position; position = updated.position;
super.syncFields(updated); super.syncFields(updated);
} }
...@@ -106,9 +105,8 @@ class SlideIn extends TransitionBase { ...@@ -106,9 +105,8 @@ class SlideIn extends TransitionBase {
} }
} }
// TODO(mpcomplete): rename FadeTransition class FadeTransition extends TransitionBase {
class FadeIn extends TransitionBase { FadeTransition({
FadeIn({
Key key, Key key,
this.opacity, this.opacity,
Duration duration, Duration duration,
...@@ -127,7 +125,7 @@ class FadeIn extends TransitionBase { ...@@ -127,7 +125,7 @@ class FadeIn extends TransitionBase {
AnimatedValue<double> opacity; AnimatedValue<double> opacity;
void syncFields(FadeIn updated) { void syncFields(FadeTransition updated) {
opacity = updated.opacity; opacity = updated.opacity;
super.syncFields(updated); super.syncFields(updated);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment