提交 02d21924 编写于 作者: H Hixie

Remove the pointless second argument to animate() in AnimatedValue.

- Rename animate() to watch().

- Fix Toggleable to actually be animated (previously, it was
  essentially luck that let it be animated -- it was piggy-backing on
  the splash, I think).

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1216533003.
上级 8ad31479
......@@ -7,12 +7,9 @@ import 'dart:async';
import '../animation/animated_value.dart';
import 'basic.dart';
typedef void SetterFunction(double value);
class _AnimationEntry {
_AnimationEntry(this.value, this.setter);
_AnimationEntry(this.value);
final AnimatedValue value;
final SetterFunction setter;
StreamSubscription<double> subscription;
}
......@@ -24,16 +21,19 @@ abstract class AnimatedComponent extends Component {
List<_AnimationEntry> _animatedFields = new List<_AnimationEntry>();
animate(AnimatedValue value, SetterFunction setter) {
watch(AnimatedValue value) {
assert(!mounted);
setter(value.value);
_animatedFields.add(new _AnimationEntry(value, setter));
// TODO(ianh): we really should assert that we're not doing this
// in the constructor since doing it there is pointless and
// expensive, since we'll be doing it for every copy of the object
// even though only the first one will use it (since we're
// stateful, the others will all be discarded early).
_animatedFields.add(new _AnimationEntry(value));
}
void didMount() {
for (_AnimationEntry entry in _animatedFields) {
entry.subscription = entry.value.onValueChanged.listen((_) {
entry.setter(entry.value.value);
scheduleBuild();
});
}
......
......@@ -114,9 +114,7 @@ class Drawer extends AnimatedComponent {
this.children,
this.level: 0
}) : super(key: key) {
animate(controller.position, (double value) {
_position = value;
});
watch(controller.position);
}
List<Widget> children;
......@@ -130,13 +128,11 @@ class Drawer extends AnimatedComponent {
super.syncFields(source);
}
double _position;
Widget build() {
Matrix4 transform = new Matrix4.identity();
transform.translate(_position);
transform.translate(controller.position.value);
double scaler = _position / _kWidth + 1;
double scaler = controller.position.value / _kWidth + 1;
Color maskColor = new Color.fromARGB((0x7F * scaler).floor(), 0, 0, 0);
var mask = new Listener(
......
......@@ -60,10 +60,7 @@ class PopupMenu extends AnimatedComponent {
backgroundColor: Grey[50],
borderRadius: 2.0,
boxShadow: shadows[level]));
animate(controller.position, (double value) {
_position = value;
});
watch(controller.position);
}
PopupMenuController controller;
......@@ -78,16 +75,15 @@ class PopupMenu extends AnimatedComponent {
super.syncFields(source);
}
double _position;
BoxPainter _painter;
double _opacityFor(int i) {
if (_position == null || _position == 1.0)
if (controller.position.value == null || controller.position.value == 1.0)
return 1.0;
double unit = 1.0 / items.length;
double duration = 1.5 * unit;
double start = i * unit;
return math.max(0.0, math.min(1.0, (_position - start) / duration));
return math.max(0.0, math.min(1.0, (controller.position.value - start) / duration));
}
Widget build() {
......@@ -98,12 +94,12 @@ class PopupMenu extends AnimatedComponent {
}));
return new Opacity(
opacity: math.min(1.0, _position * 3.0),
opacity: math.min(1.0, controller.position.value * 3.0),
child: new ShrinkWrapWidth(
child: new CustomPaint(
callback: (sky.Canvas canvas, Size size) {
double width = math.min(size.width, size.width * (0.5 + _position * 2.0));
double height = math.min(size.height, size.height * _position * 1.5);
double width = math.min(size.width, size.width * (0.5 + controller.position.value * 2.0));
double height = math.min(size.height, size.height * controller.position.value * 1.5);
_painter.paint(canvas, new Rect.fromLTRB(size.width - width, 0.0, width, height));
},
child: new Container(
......
......@@ -21,6 +21,7 @@ abstract class Toggleable extends AnimatedComponent {
this.onChanged
}) : super(key: key) {
toggleAnimation = new AnimatedValue(value ? 1.0 : 0.0);
watch(toggleAnimation);
}
bool value;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册