Port examples to the new animation API
These now use Animation and AnimationController instead of PerformanceView and Performance.
This commit is contained in:
@@ -12,21 +12,21 @@ final List<String> _iconNames = <String>["event", "home", "android", "alarm", "f
|
||||
class TabViewDemo extends StatelessComponent {
|
||||
Widget _buildTabIndicator(BuildContext context, String iconName) {
|
||||
final Color color = Theme.of(context).primaryColor;
|
||||
final AnimatedColorValue _selectedColor = new AnimatedColorValue(Colors.transparent, end: color, curve: Curves.ease);
|
||||
final AnimatedColorValue _previousColor = new AnimatedColorValue(color, end: Colors.transparent, curve: Curves.ease);
|
||||
final ColorTween _selectedColor = new ColorTween(begin: Colors.transparent, end: color);
|
||||
final ColorTween _previousColor = new ColorTween(begin: color, end: Colors.transparent);
|
||||
final TabBarSelectionState selection = TabBarSelection.of(context);
|
||||
|
||||
return new BuilderTransition(
|
||||
performance: selection.performance,
|
||||
variables: <AnimatedColorValue>[_selectedColor, _previousColor],
|
||||
Animation animation = new CurvedAnimation(parent: selection.animation, curve: Curves.ease);
|
||||
return new AnimationWatchingBuilder(
|
||||
watchable: animation,
|
||||
builder: (BuildContext context) {
|
||||
Color background = selection.value == iconName ? _selectedColor.end : _selectedColor.begin;
|
||||
if (selection.valueIsChanging) {
|
||||
// Then the selection's performance is animating from previousValue to value.
|
||||
if (selection.value == iconName)
|
||||
background = _selectedColor.value;
|
||||
background = _selectedColor.evaluate(animation);
|
||||
else if (selection.previousValue == iconName)
|
||||
background = _previousColor.value;
|
||||
background = _previousColor.evaluate(animation);
|
||||
}
|
||||
return new Container(
|
||||
width: 12.0,
|
||||
|
||||
@@ -16,7 +16,7 @@ class _ProgressIndicatorAppState extends State<ProgressIndicatorApp> {
|
||||
duration: const Duration(milliseconds: 1500)
|
||||
)..play(AnimationDirection.forward);
|
||||
|
||||
animation = new ACurve(
|
||||
animation = new CurvedAnimation(
|
||||
parent: controller,
|
||||
curve: new Interval(0.0, 0.9, curve: Curves.ease),
|
||||
reverseCurve: Curves.ease
|
||||
|
||||
@@ -26,29 +26,28 @@ class SmoothBlock extends StatefulComponent {
|
||||
class CardTransition extends StatelessComponent {
|
||||
CardTransition({
|
||||
this.child,
|
||||
this.performance,
|
||||
this.animation,
|
||||
this.x,
|
||||
this.opacity,
|
||||
this.scale
|
||||
});
|
||||
|
||||
final Widget child;
|
||||
final Performance performance;
|
||||
final AnimatedValue<double> x;
|
||||
final AnimatedValue<double> opacity;
|
||||
final AnimatedValue<double> scale;
|
||||
final Animation animation;
|
||||
final Evaluatable<double> x;
|
||||
final Evaluatable<double> opacity;
|
||||
final Evaluatable<double> scale;
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return new BuilderTransition(
|
||||
performance: performance,
|
||||
variables: <AnimatedValue<double>>[x, opacity, scale],
|
||||
return new AnimationWatchingBuilder(
|
||||
watchable: animation,
|
||||
builder: (BuildContext context) {
|
||||
double currentScale = scale.evaluate(animation);
|
||||
Matrix4 transform = new Matrix4.identity()
|
||||
..translate(x.value)
|
||||
..scale(scale.value, scale.value);
|
||||
..translate(x.evaluate(animation))
|
||||
..scale(currentScale, currentScale);
|
||||
return new Opacity(
|
||||
opacity: opacity.value,
|
||||
opacity: opacity.evaluate(animation),
|
||||
child: new Transform(
|
||||
transform: transform,
|
||||
child: child
|
||||
@@ -63,22 +62,22 @@ class SmoothBlockState extends State<SmoothBlock> {
|
||||
|
||||
double _height = 100.0;
|
||||
|
||||
Widget _handleEnter(PerformanceView performance, Widget child) {
|
||||
Widget _handleEnter(Animation animation, Widget child) {
|
||||
return new CardTransition(
|
||||
x: new AnimatedValue<double>(-200.0, end: 0.0, curve: Curves.ease),
|
||||
opacity: new AnimatedValue<double>(0.0, end: 1.0, curve: Curves.ease),
|
||||
scale: new AnimatedValue<double>(0.8, end: 1.0, curve: Curves.ease),
|
||||
performance: performance,
|
||||
x: new Tween<double>(begin: -200.0, end: 0.0),
|
||||
opacity: new Tween<double>(begin: 0.0, end: 1.0),
|
||||
scale: new Tween<double>(begin: 0.8, end: 1.0),
|
||||
animation: new CurvedAnimation(parent: animation, curve: Curves.ease),
|
||||
child: child
|
||||
);
|
||||
}
|
||||
|
||||
Widget _handleExit(PerformanceView performance, Widget child) {
|
||||
Widget _handleExit(Animation animation, Widget child) {
|
||||
return new CardTransition(
|
||||
x: new AnimatedValue<double>(0.0, end: 200.0, curve: Curves.ease),
|
||||
opacity: new AnimatedValue<double>(1.0, end: 0.0, curve: Curves.ease),
|
||||
scale: new AnimatedValue<double>(1.0, end: 0.8, curve: Curves.ease),
|
||||
performance: performance,
|
||||
x: new Tween<double>(begin: 0.0, end: 200.0),
|
||||
opacity: new Tween<double>(begin: 1.0, end: 0.0),
|
||||
scale: new Tween<double>(begin: 1.0, end: 0.8),
|
||||
animation: new CurvedAnimation(parent: animation, curve: Curves.ease),
|
||||
child: child
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user