提交 a421da3c 编写于 作者: M Matt Perry

Renamed AnimatedType to AnimatedValue

上级 bee23880
...@@ -9,6 +9,7 @@ dart_pkg("sky") { ...@@ -9,6 +9,7 @@ dart_pkg("sky") {
"CHANGELOG.md", "CHANGELOG.md",
"bin/init.dart", "bin/init.dart",
"lib/animation/animated_simulation.dart", "lib/animation/animated_simulation.dart",
"lib/animation/animated_value.dart",
"lib/animation/animation_performance.dart", "lib/animation/animation_performance.dart",
"lib/animation/curves.dart", "lib/animation/curves.dart",
"lib/animation/forces.dart", "lib/animation/forces.dart",
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:sky/editing/input.dart'; import 'package:sky/editing/input.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animated_value.dart';
import 'package:sky/widgets/animated_component.dart'; import 'package:sky/widgets/animated_component.dart';
import 'package:sky/widgets/animation_builder.dart'; import 'package:sky/widgets/animation_builder.dart';
import 'package:sky/theme/colors.dart' as colors; import 'package:sky/theme/colors.dart' as colors;
...@@ -280,10 +280,10 @@ class StockHome extends AnimatedComponent { ...@@ -280,10 +280,10 @@ class StockHome extends AnimatedComponent {
void _handleStockPurchased() { void _handleStockPurchased() {
setState(() { setState(() {
_snackbarTransform = new AnimationBuilder() _snackbarTransform = new AnimationBuilder()
..position = new AnimatedType<Point>(const Point(0.0, 45.0), end: Point.origin); ..position = new AnimatedValue<Point>(const Point(0.0, 45.0), end: Point.origin);
var performance = _snackbarTransform.createPerformance( var performance = _snackbarTransform.createPerformance(
[_snackbarTransform.position], duration: _kSnackbarSlideDuration); [_snackbarTransform.position], duration: _kSnackbarSlideDuration);
watch(performance); watch(performance); // TODO(mpcomplete): need to unwatch
performance.play(); performance.play();
}); });
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/animation/curves.dart'; import 'package:sky/animation/curves.dart';
import 'package:sky/base/lerp.dart'; import 'package:sky/base/lerp.dart';
...@@ -100,7 +101,7 @@ class CardCollectionApp extends App { ...@@ -100,7 +101,7 @@ class CardCollectionApp extends App {
assert(card.performance == null); assert(card.performance == null);
card.performance = new AnimationPerformance() card.performance = new AnimationPerformance()
..duration = const Duration(milliseconds: 300) ..duration = const Duration(milliseconds: 300)
..variable = new AnimatedType<double>( ..variable = new AnimatedValue<double>(
card.height + kCardMargins.top + kCardMargins.bottom, card.height + kCardMargins.top + kCardMargins.bottom,
end: 0.0, end: 0.0,
curve: ease, curve: ease,
......
// 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.
import "dart:sky";
import 'package:sky/animation/curves.dart';
import 'package:sky/base/lerp.dart';
abstract class AnimatedVariable {
void setProgress(double t);
String toString();
}
class Interval {
final double start;
final double end;
double adjustTime(double t) {
return ((t - start) / (end - start)).clamp(0.0, 1.0);
}
Interval(this.start, this.end) {
assert(start >= 0.0);
assert(start <= 1.0);
assert(end >= 0.0);
assert(end <= 1.0);
}
}
class AnimatedValue<T extends dynamic> extends AnimatedVariable {
AnimatedValue(this.begin, { this.end, this.interval, this.curve: linear }) {
value = begin;
}
T value;
T begin;
T end;
Interval interval;
Curve curve;
void setProgress(double t) {
if (end != null) {
double adjustedTime = interval == null ? t : interval.adjustTime(t);
if (adjustedTime == 1.0) {
value = end;
} else {
// TODO(mpcomplete): Reverse the timeline and curve.
value = begin + (end - begin) * curve.transform(adjustedTime);
}
}
}
String toString() => 'AnimatedValue(begin=$begin, end=$end, value=$value)';
}
class AnimatedList extends AnimatedVariable {
List<AnimatedVariable> variables;
Interval interval;
AnimatedList(this.variables, { this.interval });
void setProgress(double t) {
double adjustedTime = interval == null ? t : interval.adjustTime(t);
for (AnimatedVariable variable in variables)
variable.setProgress(adjustedTime);
}
String toString() => 'AnimatedList([$variables])';
}
class AnimatedColor extends AnimatedValue<Color> {
AnimatedColor(Color begin, { Color end, Curve curve: linear })
: super(begin, end: end, curve: curve);
void setProgress(double t) {
value = lerpColor(begin, end, t);
}
}
...@@ -4,71 +4,9 @@ ...@@ -4,71 +4,9 @@
import 'dart:async'; import 'dart:async';
import 'package:sky/animation/timeline.dart'; import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/curves.dart';
import 'package:sky/animation/forces.dart'; import 'package:sky/animation/forces.dart';
import 'package:sky/animation/timeline.dart';
abstract class AnimatedVariable {
void setFraction(double t);
String toString();
}
class Interval {
final double start;
final double end;
double adjustTime(double t) {
return ((t - start) / (end - start)).clamp(0.0, 1.0);
}
Interval(this.start, this.end) {
assert(start >= 0.0);
assert(start <= 1.0);
assert(end >= 0.0);
assert(end <= 1.0);
}
}
class AnimatedType<T extends dynamic> extends AnimatedVariable {
AnimatedType(this.begin, { this.end, this.interval, this.curve: linear }) {
value = begin;
}
T value;
T begin;
T end;
Interval interval;
Curve curve;
void setFraction(double t) {
if (end != null) {
double adjustedTime = interval == null ? t : interval.adjustTime(t);
if (adjustedTime == 1.0) {
value = end;
} else {
// TODO(mpcomplete): Reverse the timeline and curve.
value = begin + (end - begin) * curve.transform(adjustedTime);
}
}
}
String toString() => 'AnimatedType(begin=$begin, end=$end, value=$value)';
}
class AnimatedList extends AnimatedVariable {
List<AnimatedVariable> variables;
Interval interval;
AnimatedList(this.variables, { this.interval });
void setFraction(double t) {
double adjustedTime = interval == null ? t : interval.adjustTime(t);
for (AnimatedVariable variable in variables)
variable.setFraction(adjustedTime);
}
String toString() => 'AnimatedList([$variables])';
}
// This class manages a "performance" - a collection of values that change // This class manages a "performance" - a collection of values that change
// based on a timeline. For example, a performance may handle an animation // based on a timeline. For example, a performance may handle an animation
...@@ -82,7 +20,6 @@ class AnimationPerformance { ...@@ -82,7 +20,6 @@ class AnimationPerformance {
_timeline = new Timeline(_tick); _timeline = new Timeline(_tick);
} }
// TODO(mpcomplete): make this a list, or composable somehow.
AnimatedVariable variable; AnimatedVariable variable;
// TODO(mpcomplete): duration should be on a director. // TODO(mpcomplete): duration should be on a director.
Duration duration; Duration duration;
...@@ -142,7 +79,7 @@ class AnimationPerformance { ...@@ -142,7 +79,7 @@ class AnimationPerformance {
} }
void _tick(double t) { void _tick(double t) {
variable.setFraction(t); variable.setProgress(t);
_notifyListeners(); _notifyListeners();
} }
} }
...@@ -83,6 +83,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl ...@@ -83,6 +83,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
} }
} }
// Set during layout if overflow occurred on the main axis
TextBaseline _textBaseline; TextBaseline _textBaseline;
TextBaseline get textBaseline => _textBaseline; TextBaseline get textBaseline => _textBaseline;
void set textBaseline (TextBaseline value) { void set textBaseline (TextBaseline value) {
...@@ -92,8 +93,6 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl ...@@ -92,8 +93,6 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
} }
} }
// Set during layout if overflow occurred on the main axis
double _overflow;
void setupParentData(RenderBox child) { void setupParentData(RenderBox child) {
if (child.parentData is! FlexBoxParentData) if (child.parentData is! FlexBoxParentData)
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'package:vector_math/vector_math.dart'; import 'package:vector_math/vector_math.dart';
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/animation/curves.dart'; import 'package:sky/animation/curves.dart';
import 'package:sky/base/lerp.dart'; import 'package:sky/base/lerp.dart';
...@@ -11,21 +12,21 @@ import 'package:sky/painting/box_painter.dart'; ...@@ -11,21 +12,21 @@ import 'package:sky/painting/box_painter.dart';
import 'package:sky/widgets/basic.dart'; import 'package:sky/widgets/basic.dart';
import 'package:sky/widgets/animated_component.dart'; import 'package:sky/widgets/animated_component.dart';
class AnimatedBoxConstraintsValue extends AnimatedType<BoxConstraints> { class AnimatedBoxConstraintsValue extends AnimatedValue<BoxConstraints> {
AnimatedBoxConstraintsValue(BoxConstraints begin, { BoxConstraints end, Curve curve: linear }) AnimatedBoxConstraintsValue(BoxConstraints begin, { BoxConstraints end, Curve curve: linear })
: super(begin, end: end, curve: curve); : super(begin, end: end, curve: curve);
void setFraction(double t) { void setProgress(double t) {
// TODO(abarth): We should lerp the BoxConstraints. // TODO(abarth): We should lerp the BoxConstraints.
value = end; value = end;
} }
} }
class AnimatedBoxDecorationValue extends AnimatedType<BoxDecoration> { class AnimatedBoxDecorationValue extends AnimatedValue<BoxDecoration> {
AnimatedBoxDecorationValue(BoxDecoration begin, { BoxDecoration end, Curve curve: linear }) AnimatedBoxDecorationValue(BoxDecoration begin, { BoxDecoration end, Curve curve: linear })
: super(begin, end: end, curve: curve); : super(begin, end: end, curve: curve);
void setFraction(double t) { void setProgress(double t) {
if (t == 1.0) { if (t == 1.0) {
value = end; value = end;
return; return;
...@@ -34,11 +35,11 @@ class AnimatedBoxDecorationValue extends AnimatedType<BoxDecoration> { ...@@ -34,11 +35,11 @@ class AnimatedBoxDecorationValue extends AnimatedType<BoxDecoration> {
} }
} }
class AnimatedEdgeDimsValue extends AnimatedType<EdgeDims> { class AnimatedEdgeDimsValue extends AnimatedValue<EdgeDims> {
AnimatedEdgeDimsValue(EdgeDims begin, { EdgeDims end, Curve curve: linear }) AnimatedEdgeDimsValue(EdgeDims begin, { EdgeDims end, Curve curve: linear })
: super(begin, end: end, curve: curve); : super(begin, end: end, curve: curve);
void setFraction(double t) { void setProgress(double t) {
if (t == 1.0) { if (t == 1.0) {
value = end; value = end;
return; return;
...@@ -54,7 +55,7 @@ class AnimatedEdgeDimsValue extends AnimatedType<EdgeDims> { ...@@ -54,7 +55,7 @@ class AnimatedEdgeDimsValue extends AnimatedType<EdgeDims> {
class ImplicitlyAnimatedValue<T> { class ImplicitlyAnimatedValue<T> {
final AnimationPerformance performance = new AnimationPerformance(); final AnimationPerformance performance = new AnimationPerformance();
final AnimatedType<T> _variable; final AnimatedValue<T> _variable;
ImplicitlyAnimatedValue(this._variable, Duration duration) { ImplicitlyAnimatedValue(this._variable, Duration duration) {
performance performance
...@@ -168,21 +169,21 @@ class AnimatedContainer extends AnimatedComponent { ...@@ -168,21 +169,21 @@ class AnimatedContainer extends AnimatedComponent {
void _updateTransform() { void _updateTransform() {
_updateField(transform, _transform, () { _updateField(transform, _transform, () {
_transform = new ImplicitlyAnimatedValue<Matrix4>(new AnimatedType<Matrix4>(transform), duration); _transform = new ImplicitlyAnimatedValue<Matrix4>(new AnimatedValue<Matrix4>(transform), duration);
watch(_transform.performance); watch(_transform.performance);
}); });
} }
void _updateWidth() { void _updateWidth() {
_updateField(width, _width, () { _updateField(width, _width, () {
_width = new ImplicitlyAnimatedValue<double>(new AnimatedType<double>(width), duration); _width = new ImplicitlyAnimatedValue<double>(new AnimatedValue<double>(width), duration);
watch(_width.performance); watch(_width.performance);
}); });
} }
void _updateHeight() { void _updateHeight() {
_updateField(height, _height, () { _updateField(height, _height, () {
_height = new ImplicitlyAnimatedValue<double>( new AnimatedType<double>(height), duration); _height = new ImplicitlyAnimatedValue<double>( new AnimatedValue<double>(height), duration);
watch(_height.performance); watch(_height.performance);
}); });
} }
......
...@@ -4,9 +4,8 @@ ...@@ -4,9 +4,8 @@
import 'package:vector_math/vector_math.dart'; import 'package:vector_math/vector_math.dart';
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/animation/curves.dart';
import 'package:sky/base/lerp.dart';
import 'package:sky/painting/box_painter.dart'; import 'package:sky/painting/box_painter.dart';
import 'package:sky/theme/shadows.dart'; import 'package:sky/theme/shadows.dart';
import 'package:sky/widgets/basic.dart'; import 'package:sky/widgets/basic.dart';
...@@ -18,9 +17,9 @@ class AnimationBuilder { ...@@ -18,9 +17,9 @@ class AnimationBuilder {
AnimationBuilder(); AnimationBuilder();
AnimatedType<double> opacity; AnimatedValue<double> opacity;
AnimatedType<Point> position; AnimatedValue<Point> position;
AnimatedType<double> shadow; AnimatedValue<double> shadow;
AnimatedColor backgroundColor; AnimatedColor backgroundColor;
// These don't animate, but are used to build the AnimationBuilder anyway. // These don't animate, but are used to build the AnimationBuilder anyway.
...@@ -30,7 +29,7 @@ class AnimationBuilder { ...@@ -30,7 +29,7 @@ class AnimationBuilder {
Map<AnimatedVariable, AnimationPerformance> _variableToPerformance = Map<AnimatedVariable, AnimationPerformance> _variableToPerformance =
new Map<AnimatedVariable, AnimationPerformance>(); new Map<AnimatedVariable, AnimationPerformance>();
AnimationPerformance createPerformance(List<AnimatedType> variables, AnimationPerformance createPerformance(List<AnimatedValue> variables,
{ Duration duration }) { { Duration duration }) {
AnimationPerformance performance = new AnimationPerformance() AnimationPerformance performance = new AnimationPerformance()
..duration = duration ..duration = duration
...@@ -67,7 +66,7 @@ class AnimationBuilder { ...@@ -67,7 +66,7 @@ class AnimationBuilder {
} }
void updateFields({ void updateFields({
AnimatedType<double> shadow, AnimatedValue<double> shadow,
AnimatedColor backgroundColor, AnimatedColor backgroundColor,
double borderRadius, double borderRadius,
Shape shape Shape shape
...@@ -78,7 +77,7 @@ class AnimationBuilder { ...@@ -78,7 +77,7 @@ class AnimationBuilder {
this.shape = shape; this.shape = shape;
} }
void _updateField(AnimatedType variable, AnimatedType sourceVariable) { void _updateField(AnimatedValue variable, AnimatedValue sourceVariable) {
if (variable == null) if (variable == null)
return; // TODO(mpcomplete): Should we handle transition from null? return; // TODO(mpcomplete): Should we handle transition from null?
...@@ -101,15 +100,6 @@ class AnimationBuilder { ...@@ -101,15 +100,6 @@ class AnimationBuilder {
} }
} }
class AnimatedColor extends AnimatedType<Color> {
AnimatedColor(Color begin, { Color end, Curve curve: linear })
: super(begin, end: end, curve: curve);
void setFraction(double t) {
value = lerpColor(begin, end, t);
}
}
List<BoxShadow> _computeShadow(double level) { List<BoxShadow> _computeShadow(double level) {
if (level < 1.0) // shadows[1] is the first shadow if (level < 1.0) // shadows[1] is the first shadow
return null; return null;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:sky' as sky; import 'dart:sky' as sky;
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/widgets/animated_component.dart'; import 'package:sky/widgets/animated_component.dart';
import 'package:sky/widgets/basic.dart'; import 'package:sky/widgets/basic.dart';
...@@ -13,7 +14,7 @@ import 'package:vector_math/vector_math.dart'; ...@@ -13,7 +14,7 @@ import 'package:vector_math/vector_math.dart';
const Duration _kCardDismissFadeout = const Duration(milliseconds: 200); const Duration _kCardDismissFadeout = const Duration(milliseconds: 200);
const double _kMinFlingVelocity = 700.0; const double _kMinFlingVelocity = 700.0;
const double _kMinFlingVelocityDelta = 400.0; const double _kMinFlingVelocityDelta = 400.0;
const double _kFlingVelocityScale = 1.0/300.0; const double _kFlingVelocityScale = 1.0 / 300.0;
const double _kDismissCardThreshold = 0.6; const double _kDismissCardThreshold = 0.6;
typedef void DismissedCallback(); typedef void DismissedCallback();
...@@ -30,8 +31,8 @@ class Dismissable extends AnimatedComponent { ...@@ -30,8 +31,8 @@ class Dismissable extends AnimatedComponent {
Widget child; Widget child;
DismissedCallback onDismissed; DismissedCallback onDismissed;
AnimatedType<Point> _position; AnimatedValue<Point> _position;
AnimatedType<double> _opacity; AnimatedValue<double> _opacity;
AnimationPerformance _performance; AnimationPerformance _performance;
double _width; double _width;
...@@ -39,8 +40,8 @@ class Dismissable extends AnimatedComponent { ...@@ -39,8 +40,8 @@ class Dismissable extends AnimatedComponent {
bool _dragUnderway = false; bool _dragUnderway = false;
void initState() { void initState() {
_position = new AnimatedType<Point>(Point.origin); _position = new AnimatedValue<Point>(Point.origin);
_opacity = new AnimatedType<double>(1.0, end: 0.0); _opacity = new AnimatedValue<double>(1.0, end: 0.0);
_performance = new AnimationPerformance() _performance = new AnimationPerformance()
..duration = _kCardDismissFadeout ..duration = _kCardDismissFadeout
..variable = new AnimatedList([_position, _opacity]) ..variable = new AnimatedList([_position, _opacity])
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
import 'dart:sky' as sky; import 'dart:sky' as sky;
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/theme/shadows.dart'; import 'package:sky/theme/shadows.dart';
import 'package:sky/theme/colors.dart' as colors; import 'package:sky/theme/colors.dart' as colors;
import 'package:sky/widgets/animated_component.dart'; import 'package:sky/widgets/animated_component.dart';
import 'package:sky/widgets/animation_builder.dart';
import 'package:sky/widgets/basic.dart'; import 'package:sky/widgets/basic.dart';
import 'package:sky/widgets/navigator.dart'; import 'package:sky/widgets/navigator.dart';
import 'package:sky/widgets/scrollable_viewport.dart'; import 'package:sky/widgets/scrollable_viewport.dart';
...@@ -30,7 +30,7 @@ import 'package:vector_math/vector_math.dart'; ...@@ -30,7 +30,7 @@ import 'package:vector_math/vector_math.dart';
const double _kWidth = 304.0; const double _kWidth = 304.0;
const double _kMinFlingVelocity = 365.0; const double _kMinFlingVelocity = 365.0;
const double _kFlingVelocityScale = 1.0/300.0; const double _kFlingVelocityScale = 1.0 / 300.0;
const Duration _kBaseSettleDuration = const Duration(milliseconds: 246); const Duration _kBaseSettleDuration = const Duration(milliseconds: 246);
const Point _kOpenPosition = Point.origin; const Point _kOpenPosition = Point.origin;
const Point _kClosedPosition = const Point(-_kWidth, 0.0); const Point _kClosedPosition = const Point(-_kWidth, 0.0);
...@@ -60,12 +60,12 @@ class Drawer extends AnimatedComponent { ...@@ -60,12 +60,12 @@ class Drawer extends AnimatedComponent {
DrawerStatusChangedCallback onStatusChanged; DrawerStatusChangedCallback onStatusChanged;
Navigator navigator; Navigator navigator;
AnimatedType<Point> _position; AnimatedValue<Point> _position;
AnimatedColor _maskColor; AnimatedColor _maskColor;
AnimationPerformance _performance; AnimationPerformance _performance;
void initState() { void initState() {
_position = new AnimatedType<Point>(_kClosedPosition, end: _kOpenPosition); _position = new AnimatedValue<Point>(_kClosedPosition, end: _kOpenPosition);
_maskColor = new AnimatedColor(colors.transparent, end: const Color(0x7F000000)); _maskColor = new AnimatedColor(colors.transparent, end: const Color(0x7F000000));
_performance = new AnimationPerformance() _performance = new AnimationPerformance()
..duration = _kBaseSettleDuration ..duration = _kBaseSettleDuration
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:sky' as sky; import 'dart:sky' as sky;
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/animation/curves.dart'; import 'package:sky/animation/curves.dart';
import 'package:sky/rendering/box.dart'; import 'package:sky/rendering/box.dart';
...@@ -29,7 +30,7 @@ double _getSplashTargetSize(Size bounds, Point position) { ...@@ -29,7 +30,7 @@ double _getSplashTargetSize(Size bounds, Point position) {
class InkSplash { class InkSplash {
InkSplash(this.pointer, this.position, this.well) { InkSplash(this.pointer, this.position, this.well) {
_targetRadius = _getSplashTargetSize(well.size, position); _targetRadius = _getSplashTargetSize(well.size, position);
_radius = new AnimatedType<double>( _radius = new AnimatedValue<double>(
_kSplashInitialSize, end: _targetRadius, curve: easeOut); _kSplashInitialSize, end: _targetRadius, curve: easeOut);
_performance = new AnimationPerformance() _performance = new AnimationPerformance()
...@@ -45,7 +46,7 @@ class InkSplash { ...@@ -45,7 +46,7 @@ class InkSplash {
double _targetRadius; double _targetRadius;
double _pinnedRadius; double _pinnedRadius;
AnimatedType<double> _radius; AnimatedValue<double> _radius;
AnimationPerformance _performance; AnimationPerformance _performance;
void _updateVelocity(double velocity) { void _updateVelocity(double velocity) {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/animation/curves.dart'; import 'package:sky/animation/curves.dart';
import 'package:sky/widgets/animated_component.dart'; import 'package:sky/widgets/animated_component.dart';
...@@ -59,17 +60,17 @@ class Transition extends AnimatedComponent { ...@@ -59,17 +60,17 @@ class Transition extends AnimatedComponent {
Function onDismissed; Function onDismissed;
Function onCompleted; Function onCompleted;
AnimatedType<Point> _position; AnimatedValue<Point> _position;
AnimatedType<double> _opacity; AnimatedValue<double> _opacity;
AnimationPerformance _performance; AnimationPerformance _performance;
void initState() { void initState() {
_position = new AnimatedType<Point>( _position = new AnimatedValue<Point>(
_kTransitionStartPoint, _kTransitionStartPoint,
end: Point.origin, end: Point.origin,
curve: easeOut curve: easeOut
); );
_opacity = new AnimatedType<double>(0.0, end: 1.0) _opacity = new AnimatedValue<double>(0.0, end: 1.0)
..curve = easeOut; ..curve = easeOut;
_performance = new AnimationPerformance() _performance = new AnimationPerformance()
..duration = _kTransitionDuration ..duration = _kTransitionDuration
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:sky' as sky; import 'dart:sky' as sky;
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/painting/box_painter.dart'; import 'package:sky/painting/box_painter.dart';
import 'package:sky/theme/colors.dart'; import 'package:sky/theme/colors.dart';
...@@ -48,10 +49,10 @@ class PopupMenu extends AnimatedComponent { ...@@ -48,10 +49,10 @@ class PopupMenu extends AnimatedComponent {
int level; int level;
Navigator navigator; Navigator navigator;
AnimatedType<double> _opacity; AnimatedValue<double> _opacity;
AnimatedType<double> _width; AnimatedValue<double> _width;
AnimatedType<double> _height; AnimatedValue<double> _height;
List<AnimatedType<double>> _itemOpacities; List<AnimatedValue<double>> _itemOpacities;
AnimatedList _animationList; AnimatedList _animationList;
AnimationPerformance _performance; AnimationPerformance _performance;
...@@ -88,14 +89,14 @@ class PopupMenu extends AnimatedComponent { ...@@ -88,14 +89,14 @@ class PopupMenu extends AnimatedComponent {
void _updateAnimationVariables() { void _updateAnimationVariables() {
double unit = 1.0 / (items.length + 1.5); // 1.0 for the width and 0.5 for the last item's fade. double unit = 1.0 / (items.length + 1.5); // 1.0 for the width and 0.5 for the last item's fade.
_opacity = new AnimatedType<double>(0.0, end: 1.0); _opacity = new AnimatedValue<double>(0.0, end: 1.0);
_width = new AnimatedType<double>(0.0, end: 1.0, interval: new Interval(0.0, unit)); _width = new AnimatedValue<double>(0.0, end: 1.0, interval: new Interval(0.0, unit));
_height = new AnimatedType<double>(0.0, end: 1.0, interval: new Interval(0.0, unit * items.length)); _height = new AnimatedValue<double>(0.0, end: 1.0, interval: new Interval(0.0, unit * items.length));
_itemOpacities = new List<AnimatedType<double>>(); _itemOpacities = new List<AnimatedValue<double>>();
for (int i = 0; i < items.length; ++i) { for (int i = 0; i < items.length; ++i) {
double start = (i + 1) * unit; double start = (i + 1) * unit;
double end = (start + 1.5 * unit).clamp(0.0, 1.0); double end = (start + 1.5 * unit).clamp(0.0, 1.0);
_itemOpacities.add(new AnimatedType<double>( _itemOpacities.add(new AnimatedValue<double>(
0.0, end: 1.0, interval: new Interval(start, end))); 0.0, end: 1.0, interval: new Interval(start, end)));
} }
List<AnimatedVariable> variables = new List<AnimatedVariable>() List<AnimatedVariable> variables = new List<AnimatedVariable>()
...@@ -121,7 +122,7 @@ class PopupMenu extends AnimatedComponent { ...@@ -121,7 +122,7 @@ class PopupMenu extends AnimatedComponent {
PopupMenuStatus status = _status; PopupMenuStatus status = _status;
if (_lastStatus != null && status != _lastStatus) { if (_lastStatus != null && status != _lastStatus) {
if (status == PopupMenuStatus.inactive && if (status == PopupMenuStatus.inactive &&
navigator != null && navigator != null &&
navigator.currentRoute.key == this) navigator.currentRoute.key == this)
navigator.pop(); navigator.pop();
if (onStatusChanged != null) if (onStatusChanged != null)
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:sky' as sky; import 'dart:sky' as sky;
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/animation/curves.dart'; import 'package:sky/animation/curves.dart';
import 'package:sky/widgets/animated_component.dart'; import 'package:sky/widgets/animated_component.dart';
...@@ -24,14 +25,14 @@ abstract class Toggleable extends AnimatedComponent { ...@@ -24,14 +25,14 @@ abstract class Toggleable extends AnimatedComponent {
bool value; bool value;
ValueChanged onChanged; ValueChanged onChanged;
AnimatedType<double> _position; AnimatedValue<double> _position;
AnimatedType<double> get position => _position; AnimatedValue<double> get position => _position;
AnimationPerformance _performance; AnimationPerformance _performance;
AnimationPerformance get performance => _performance; AnimationPerformance get performance => _performance;
void initState() { void initState() {
_position = new AnimatedType<double>(0.0, end: 1.0); _position = new AnimatedValue<double>(0.0, end: 1.0);
_performance = new AnimationPerformance() _performance = new AnimationPerformance()
..variable = position ..variable = position
..duration = _kCheckDuration ..duration = _kCheckDuration
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册