| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:vector_math/vector_math.dart'; | |
| 8 | |
| 9 import '../animation/animated_value.dart'; | 7 import '../animation/animated_value.dart'; |
| 10 import '../animation/animation_performance.dart'; | |
| 11 import '../animation/curves.dart'; | |
| 12 import 'basic.dart'; | 8 import 'basic.dart'; |
| 13 | 9 |
| 14 class _AnimationEntry { | 10 class _AnimationEntry { |
| 15 _AnimationEntry(this.value); | 11 _AnimationEntry(this.value); |
| 16 final AnimatedValue value; | 12 final AnimatedValue value; |
| 17 StreamSubscription<double> subscription; | 13 StreamSubscription<double> subscription; |
| 18 } | 14 } |
| 19 | 15 |
| 20 abstract class AnimatedComponent extends StatefulComponent { | 16 abstract class AnimatedComponent extends StatefulComponent { |
| 21 | 17 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 47 void didUnmount() { | 43 void didUnmount() { |
| 48 for (_AnimationEntry entry in _animatedFields) { | 44 for (_AnimationEntry entry in _animatedFields) { |
| 49 assert(entry.subscription != null); | 45 assert(entry.subscription != null); |
| 50 entry.subscription.cancel(); | 46 entry.subscription.cancel(); |
| 51 entry.subscription = null; | 47 entry.subscription = null; |
| 52 } | 48 } |
| 53 super.didUnmount(); | 49 super.didUnmount(); |
| 54 } | 50 } |
| 55 | 51 |
| 56 } | 52 } |
| 57 | |
| 58 // Types of things that can be animated in a component. Use build() to | |
| 59 // construct the final Widget based on the animation state. | |
| 60 // TODO(mpcomplete): the idea here is to eventually have an AnimatedCollection | |
| 61 // which assembles a container based on a list of animated things. e.g. if you | |
| 62 // want to animate position, opacity, and shadow, you add those animators to an | |
| 63 // AnimatedCollection and just call collection.build() to construct your | |
| 64 // widget. | |
| 65 | |
| 66 class AnimatedPosition extends AnimatedType<Point> { | |
| 67 AnimatedPosition(Point begin, Point end, {Curve curve: linear}) | |
| 68 : super(begin, end, curve: curve); | |
| 69 | |
| 70 Widget build(Widget child) { | |
| 71 Matrix4 transform = new Matrix4.identity(); | |
| 72 transform.translate(value.x, value.y); | |
| 73 return new Transform(transform: transform, child: child); | |
| 74 } | |
| 75 } | |
| OLD | NEW |