5
5
import 'dart:sky' as sky;
6
6
7
7
import 'package:sky/animation/animation_performance.dart' ;
8
- import 'package:sky/animation/curves.dart' ;
9
8
import 'package:sky/theme/shadows.dart' ;
10
9
import 'package:sky/theme/colors.dart' as colors;
11
10
import 'package:sky/widgets/animated_component.dart' ;
@@ -30,14 +29,11 @@ import 'package:vector_math/vector_math.dart';
30
29
// The right nav can vary depending on content.
31
30
32
31
const double _kWidth = 304.0 ;
33
- const double _kMinFlingVelocity = 1.2 ;
32
+ const double _kMinFlingVelocity = 365.0 ;
33
+ const double _kFlingVelocityScale = 1.0 / 300.0 ;
34
34
const Duration _kBaseSettleDuration = const Duration (milliseconds: 246 );
35
- // TODO(mpcomplete): The curve must be linear if we want the drawer to track
36
- // the user's finger. Odeon remedies this by attaching spring forces to the
37
- // initial timeline when animating (so it doesn't look linear).
38
35
const Point _kOpenPosition = Point .origin;
39
36
const Point _kClosedPosition = const Point (- _kWidth, 0.0 );
40
- const Curve _kAnimationCurve = linear;
41
37
42
38
typedef void DrawerStatusChangeHandler (bool showing);
43
39
@@ -69,7 +65,7 @@ class Drawer extends AnimatedComponent {
69
65
AnimationPerformance _performance;
70
66
71
67
void initState () {
72
- _position = new AnimatedType <Point >(_kClosedPosition, end: _kOpenPosition, curve : _kAnimationCurve );
68
+ _position = new AnimatedType <Point >(_kClosedPosition, end: _kOpenPosition);
73
69
_maskColor = new AnimatedColor (colors.transparent, end: const Color (0x7F000000 ));
74
70
_performance = new AnimationPerformance ()
75
71
..duration = _kBaseSettleDuration
@@ -95,11 +91,18 @@ class Drawer extends AnimatedComponent {
95
91
void _show () {
96
92
if (navigator != null )
97
93
navigator.pushState (this , (_) => _performance.reverse ());
98
- _performance. play ( );
94
+ _fling ( 1.0 );
99
95
}
100
96
101
97
void _hide () {
102
- _performance.reverse ();
98
+ _fling (- 1.0 );
99
+ }
100
+
101
+ // We fling the performance timeline instead of animating it to give it a
102
+ // nice spring effect. We can't use curves for this because we need a linear
103
+ // curve in order to track the user's finger while dragging.
104
+ void _fling (double direction) {
105
+ _performance.fling (velocity: direction.sign);
103
106
}
104
107
105
108
Widget build () {
@@ -151,9 +154,9 @@ class Drawer extends AnimatedComponent {
151
154
DrawerStatus get _status => _performance.isDismissed ? DrawerStatus .inactive : DrawerStatus .active;
152
155
bool get _isMostlyClosed => xPosition <= - _kWidth/ 2 ;
153
156
154
- void _settle () => _isMostlyClosed ? _performance. reverse () : _performance. play ( );
157
+ void _settle () => _fling ( _isMostlyClosed ? - 1.0 : 1.0 );
155
158
156
- void handleMaskTap (_) => _performance. reverse ( );
159
+ void handleMaskTap (_) => _fling ( - 1.0 );
157
160
158
161
// TODO(mpcomplete): Figure out how to generalize these handlers on a
159
162
// "PannableThingy" interface.
@@ -176,8 +179,7 @@ class Drawer extends AnimatedComponent {
176
179
}
177
180
178
181
void handleFlingStart (event) {
179
- double velocityX = event.velocityX / _kWidth;
180
- if (velocityX.abs () >= _kMinFlingVelocity)
181
- _performance.fling (velocity: velocityX);
182
+ if (event.velocityX.abs () >= _kMinFlingVelocity)
183
+ _performance.fling (velocity: event.velocityX * _kFlingVelocityScale);
182
184
}
183
185
}
0 commit comments