Rename some animation classes.
* Intentions => Behaviors * SlideIn => SlideTransition * FadeIn => FadeTransition * removed unused AnimatedContainer intentions
This commit is contained in:
@@ -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> {
|
||||
final AnimationPerformance performance = new AnimationPerformance();
|
||||
final AnimatedValue<T> _variable;
|
||||
@@ -93,13 +98,8 @@ class ImplicitlyAnimatedValue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AnimationIntention {
|
||||
void initFields(AnimatedContainer original);
|
||||
void syncFields(AnimatedContainer original, AnimatedContainer updated);
|
||||
}
|
||||
|
||||
abstract class ImplicitlySyncFieldIntention<T> extends AnimationIntention {
|
||||
ImplicitlySyncFieldIntention(this.duration);
|
||||
abstract class ImplicitlyAnimatedFieldBehavior<T> extends AnimationBehavior {
|
||||
ImplicitlyAnimatedFieldBehavior(this.duration);
|
||||
|
||||
Duration duration;
|
||||
ImplicitlyAnimatedValue<T> field;
|
||||
@@ -131,71 +131,71 @@ abstract class ImplicitlySyncFieldIntention<T> extends AnimationIntention {
|
||||
}
|
||||
}
|
||||
|
||||
class ImplicitlySyncConstraintsIntention extends ImplicitlySyncFieldIntention<BoxConstraints> {
|
||||
ImplicitlySyncConstraintsIntention(Duration duration) : super(duration);
|
||||
class ImplicitlyAnimatedConstraintsBehavior extends ImplicitlyAnimatedFieldBehavior<BoxConstraints> {
|
||||
ImplicitlyAnimatedConstraintsBehavior(Duration duration) : super(duration);
|
||||
|
||||
BoxConstraints getter(AnimatedContainer container) => container.constraints;
|
||||
void setter(AnimatedContainer container, BoxConstraints val) { container.constraints = val; }
|
||||
AnimatedValue initField(BoxConstraints val) => new AnimatedBoxConstraintsValue(val);
|
||||
}
|
||||
|
||||
class ImplicitlySyncDecorationIntention extends ImplicitlySyncFieldIntention<BoxDecoration> {
|
||||
ImplicitlySyncDecorationIntention(Duration duration) : super(duration);
|
||||
class ImplicitlyAnimatedDecorationBehavior extends ImplicitlyAnimatedFieldBehavior<BoxDecoration> {
|
||||
ImplicitlyAnimatedDecorationBehavior(Duration duration) : super(duration);
|
||||
|
||||
BoxDecoration getter(AnimatedContainer container) => container.decoration;
|
||||
void setter(AnimatedContainer container, BoxDecoration val) { container.decoration = val; }
|
||||
AnimatedValue initField(BoxDecoration val) => new AnimatedBoxDecorationValue(val);
|
||||
}
|
||||
|
||||
class ImplicitlySyncMarginIntention extends ImplicitlySyncFieldIntention<EdgeDims> {
|
||||
ImplicitlySyncMarginIntention(Duration duration) : super(duration);
|
||||
class ImplicitlyAnimatedMarginBehavior extends ImplicitlyAnimatedFieldBehavior<EdgeDims> {
|
||||
ImplicitlyAnimatedMarginBehavior(Duration duration) : super(duration);
|
||||
|
||||
EdgeDims getter(AnimatedContainer container) => container.margin;
|
||||
void setter(AnimatedContainer container, EdgeDims val) { container.margin = val; }
|
||||
AnimatedValue initField(EdgeDims val) => new AnimatedEdgeDimsValue(val);
|
||||
}
|
||||
|
||||
class ImplicitlySyncPaddingIntention extends ImplicitlySyncFieldIntention<EdgeDims> {
|
||||
ImplicitlySyncPaddingIntention(Duration duration) : super(duration);
|
||||
class ImplicitlyAnimatedPaddingBehavior extends ImplicitlyAnimatedFieldBehavior<EdgeDims> {
|
||||
ImplicitlyAnimatedPaddingBehavior(Duration duration) : super(duration);
|
||||
|
||||
EdgeDims getter(AnimatedContainer container) => container.padding;
|
||||
void setter(AnimatedContainer container, EdgeDims val) { container.padding = val; }
|
||||
AnimatedValue initField(EdgeDims val) => new AnimatedEdgeDimsValue(val);
|
||||
}
|
||||
|
||||
class ImplicitlySyncTransformIntention extends ImplicitlySyncFieldIntention<Matrix4> {
|
||||
ImplicitlySyncTransformIntention(Duration duration) : super(duration);
|
||||
class ImplicitlyAnimatedTransformBehavior extends ImplicitlyAnimatedFieldBehavior<Matrix4> {
|
||||
ImplicitlyAnimatedTransformBehavior(Duration duration) : super(duration);
|
||||
|
||||
Matrix4 getter(AnimatedContainer container) => container.transform;
|
||||
void setter(AnimatedContainer container, Matrix4 val) { container.transform = val; }
|
||||
AnimatedValue initField(Matrix4 val) => new AnimatedMatrix4Value(val);
|
||||
}
|
||||
|
||||
class ImplicitlySyncWidthIntention extends ImplicitlySyncFieldIntention<double> {
|
||||
ImplicitlySyncWidthIntention(Duration duration) : super(duration);
|
||||
class ImplicitlyAnimatedWidthBehavior extends ImplicitlyAnimatedFieldBehavior<double> {
|
||||
ImplicitlyAnimatedWidthBehavior(Duration duration) : super(duration);
|
||||
|
||||
double getter(AnimatedContainer container) => container.width;
|
||||
void setter(AnimatedContainer container, double val) { container.width = val; }
|
||||
AnimatedValue initField(double val) => new AnimatedValue<double>(val);
|
||||
}
|
||||
|
||||
class ImplicitlySyncHeightIntention extends ImplicitlySyncFieldIntention<double> {
|
||||
ImplicitlySyncHeightIntention(Duration duration) : super(duration);
|
||||
class ImplicitlyAnimatedHeightBehavior extends ImplicitlyAnimatedFieldBehavior<double> {
|
||||
ImplicitlyAnimatedHeightBehavior(Duration duration) : super(duration);
|
||||
|
||||
double getter(AnimatedContainer container) => container.height;
|
||||
void setter(AnimatedContainer container, double val) { container.height = val; }
|
||||
AnimatedValue initField(double val) => new AnimatedValue<double>(val);
|
||||
}
|
||||
|
||||
List<AnimationIntention> implicitlySyncFieldsIntention(Duration duration) {
|
||||
List<AnimationBehavior> implicitlyAnimate(Duration duration) {
|
||||
return [
|
||||
new ImplicitlySyncConstraintsIntention(duration),
|
||||
new ImplicitlySyncDecorationIntention(duration),
|
||||
new ImplicitlySyncMarginIntention(duration),
|
||||
new ImplicitlySyncPaddingIntention(duration),
|
||||
new ImplicitlySyncTransformIntention(duration),
|
||||
new ImplicitlySyncWidthIntention(duration),
|
||||
new ImplicitlySyncHeightIntention(duration)
|
||||
new ImplicitlyAnimatedConstraintsBehavior(duration),
|
||||
new ImplicitlyAnimatedDecorationBehavior(duration),
|
||||
new ImplicitlyAnimatedMarginBehavior(duration),
|
||||
new ImplicitlyAnimatedPaddingBehavior(duration),
|
||||
new ImplicitlyAnimatedTransformBehavior(duration),
|
||||
new ImplicitlyAnimatedWidthBehavior(duration),
|
||||
new ImplicitlyAnimatedHeightBehavior(duration)
|
||||
];
|
||||
}
|
||||
|
||||
@@ -203,8 +203,7 @@ class AnimatedContainer extends AnimatedComponent {
|
||||
AnimatedContainer({
|
||||
Key key,
|
||||
this.child,
|
||||
this.intentions,
|
||||
this.tag,
|
||||
this.behavior,
|
||||
this.constraints,
|
||||
this.decoration,
|
||||
this.width,
|
||||
@@ -223,17 +222,16 @@ class AnimatedContainer extends AnimatedComponent {
|
||||
double width;
|
||||
double height;
|
||||
|
||||
List<AnimationIntention> intentions;
|
||||
dynamic tag; // Used by intentions to determine desired state.
|
||||
List<AnimationBehavior> behavior;
|
||||
|
||||
void initState() {
|
||||
for (AnimationIntention i in intentions)
|
||||
for (AnimationBehavior i in behavior)
|
||||
i.initFields(this);
|
||||
}
|
||||
|
||||
void syncFields(AnimatedContainer updated) {
|
||||
child = updated.child;
|
||||
for (AnimationIntention i in intentions)
|
||||
for (AnimationBehavior i in behavior)
|
||||
i.syncFields(this, updated);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
// 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 {
|
||||
onGestureFlingStart: _handleFlingStart,
|
||||
child: new SizeObserver(
|
||||
callback: _handleSizeChanged,
|
||||
child: new SlideIn(
|
||||
child: new SlideTransition(
|
||||
performance: _fadePerformance,
|
||||
position: new AnimatedValue<Point>(Point.origin, end: _activeCardDragEndPoint),
|
||||
child: new FadeIn(
|
||||
child: new FadeTransition(
|
||||
performance: _fadePerformance,
|
||||
onCompleted: _handleFadeCompleted,
|
||||
opacity: new AnimatedValue<double>(1.0, end: 0.0),
|
||||
|
||||
@@ -94,13 +94,13 @@ class Drawer extends StatefulComponent {
|
||||
onGestureTap: handleMaskTap
|
||||
);
|
||||
|
||||
Widget content = new SlideIn(
|
||||
Widget content = new SlideTransition(
|
||||
performance: _performance,
|
||||
direction: showing ? Direction.forward : Direction.reverse,
|
||||
position: new AnimatedValue<Point>(_kClosedPosition, end: _kOpenPosition),
|
||||
onDismissed: _onDismissed,
|
||||
child: new AnimatedContainer(
|
||||
intentions: implicitlySyncFieldsIntention(const Duration(milliseconds: 200)),
|
||||
behavior: implicitlyAnimate(const Duration(milliseconds: 200)),
|
||||
decoration: new BoxDecoration(
|
||||
backgroundColor: Theme.of(this).canvasColor,
|
||||
boxShadow: shadows[level]),
|
||||
|
||||
@@ -49,7 +49,7 @@ class Material extends Component {
|
||||
|
||||
Widget build() {
|
||||
return new AnimatedContainer(
|
||||
intentions: implicitlySyncFieldsIntention(const Duration(milliseconds: 200)),
|
||||
behavior: implicitlyAnimate(const Duration(milliseconds: 200)),
|
||||
decoration: new BoxDecoration(
|
||||
backgroundColor: _backgroundColor,
|
||||
borderRadius: edges[type],
|
||||
|
||||
@@ -89,11 +89,11 @@ class Transition extends TransitionBase {
|
||||
Widget build() {
|
||||
// TODO(jackson): Hit testing should ignore transform
|
||||
// TODO(jackson): Block input unless content is interactive
|
||||
return new SlideIn(
|
||||
return new SlideTransition(
|
||||
performance: performance,
|
||||
direction: direction,
|
||||
position: new AnimatedValue<Point>(_kTransitionStartPoint, end: Point.origin, curve: easeOut),
|
||||
child: new FadeIn(
|
||||
child: new FadeTransition(
|
||||
performance: performance,
|
||||
direction: direction,
|
||||
opacity: new AnimatedValue<double>(0.0, end: 1.0, curve: easeOut),
|
||||
|
||||
@@ -74,7 +74,7 @@ class SnackBar extends Component {
|
||||
)
|
||||
]..addAll(actions);
|
||||
|
||||
return new SlideIn(
|
||||
return new SlideTransition(
|
||||
duration: _kSlideInDuration,
|
||||
direction: showing ? Direction.forward : Direction.reverse,
|
||||
position: new AnimatedValue<Point>(const Point(0.0, 50.0),
|
||||
|
||||
@@ -70,11 +70,10 @@ abstract class TransitionBase extends AnimatedComponent {
|
||||
Widget build();
|
||||
}
|
||||
|
||||
// TODO(mpcomplete): rename SlideTransition
|
||||
class SlideIn extends TransitionBase {
|
||||
class SlideTransition extends TransitionBase {
|
||||
// TODO(mpcomplete): this constructor is mostly boilerplate, passing values
|
||||
// to super. Is there a simpler way?
|
||||
SlideIn({
|
||||
SlideTransition({
|
||||
Key key,
|
||||
this.position,
|
||||
Duration duration,
|
||||
@@ -93,7 +92,7 @@ class SlideIn extends TransitionBase {
|
||||
|
||||
AnimatedValue<Point> position;
|
||||
|
||||
void syncFields(SlideIn updated) {
|
||||
void syncFields(SlideTransition updated) {
|
||||
position = updated.position;
|
||||
super.syncFields(updated);
|
||||
}
|
||||
@@ -106,9 +105,8 @@ class SlideIn extends TransitionBase {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(mpcomplete): rename FadeTransition
|
||||
class FadeIn extends TransitionBase {
|
||||
FadeIn({
|
||||
class FadeTransition extends TransitionBase {
|
||||
FadeTransition({
|
||||
Key key,
|
||||
this.opacity,
|
||||
Duration duration,
|
||||
@@ -127,7 +125,7 @@ class FadeIn extends TransitionBase {
|
||||
|
||||
AnimatedValue<double> opacity;
|
||||
|
||||
void syncFields(FadeIn updated) {
|
||||
void syncFields(FadeTransition updated) {
|
||||
opacity = updated.opacity;
|
||||
super.syncFields(updated);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user