| 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:sky' as sky; | 5 import 'dart:sky' as sky; |
| 6 | 6 |
| 7 import 'package:sky/animation/animation_performance.dart'; | 7 import 'package:sky/animation/animation_performance.dart'; |
| 8 import 'package:sky/animation/curves.dart'; | 8 import 'package:sky/animation/curves.dart'; |
| 9 import 'package:sky/widgets/animated_component.dart'; | 9 import 'package:sky/widgets/animated_component.dart'; |
| 10 import 'package:sky/widgets/basic.dart'; | 10 import 'package:sky/widgets/basic.dart'; |
| 11 | 11 |
| 12 typedef void ValueChanged(value); | 12 typedef void ValueChanged(value); |
| 13 | 13 |
| 14 const Duration _kCheckDuration = const Duration(milliseconds: 200); | 14 const Duration _kCheckDuration = const Duration(milliseconds: 200); |
| 15 | 15 |
| 16 abstract class Toggleable extends AnimatedComponent { | 16 abstract class Toggleable extends AnimatedComponent { |
| 17 | 17 |
| 18 Toggleable({ | 18 Toggleable({ |
| 19 String key, | 19 String key, |
| 20 this.value, | 20 this.value, |
| 21 this.onChanged | 21 this.onChanged |
| 22 }) : super(key: key) { | 22 }) : super(key: key); |
| 23 _position = new AnimatedType<double>(0.0, end: 1.0); | |
| 24 _performance = new AnimationPerformance() | |
| 25 ..variable = position | |
| 26 ..duration = _kCheckDuration | |
| 27 ..progress = value ? 1.0 : 0.0; | |
| 28 watchPerformance(performance); | |
| 29 } | |
| 30 | 23 |
| 31 bool value; | 24 bool value; |
| 32 ValueChanged onChanged; | 25 ValueChanged onChanged; |
| 33 | 26 |
| 34 AnimatedType<double> _position; | 27 AnimatedType<double> _position; |
| 35 AnimatedType<double> get position => _position; | 28 AnimatedType<double> get position => _position; |
| 36 | 29 |
| 37 AnimationPerformance _performance; | 30 AnimationPerformance _performance; |
| 38 AnimationPerformance get performance => _performance; | 31 AnimationPerformance get performance => _performance; |
| 39 | 32 |
| 33 void initState() { |
| 34 _position = new AnimatedType<double>(0.0, end: 1.0); |
| 35 _performance = new AnimationPerformance() |
| 36 ..variable = position |
| 37 ..duration = _kCheckDuration |
| 38 ..progress = value ? 1.0 : 0.0; |
| 39 watch(performance); |
| 40 } |
| 41 |
| 40 void syncFields(Toggleable source) { | 42 void syncFields(Toggleable source) { |
| 41 onChanged = source.onChanged; | 43 onChanged = source.onChanged; |
| 42 if (value != source.value) { | 44 if (value != source.value) { |
| 43 value = source.value; | 45 value = source.value; |
| 44 // TODO(abarth): Setting the curve on the position means there's a | 46 // TODO(abarth): Setting the curve on the position means there's a |
| 45 // discontinuity when we reverse the timeline. | 47 // discontinuity when we reverse the timeline. |
| 46 if (value) { | 48 if (value) { |
| 47 position.curve = curveUp; | 49 position.curve = curveUp; |
| 48 performance.play(); | 50 performance.play(); |
| 49 } else { | 51 } else { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 76 height: size.height, | 78 height: size.height, |
| 77 child: new CustomPaint( | 79 child: new CustomPaint( |
| 78 token: position.value, | 80 token: position.value, |
| 79 callback: customPaintCallback | 81 callback: customPaintCallback |
| 80 ) | 82 ) |
| 81 ), | 83 ), |
| 82 onGestureTap: _handleClick | 84 onGestureTap: _handleClick |
| 83 ); | 85 ); |
| 84 } | 86 } |
| 85 } | 87 } |
| OLD | NEW |