55import 'dart:sky' as sky;
66
77import 'package:sky/animation/animation_performance.dart' ;
8- import 'package:sky/animation/curves.dart' ;
98import 'package:sky/theme/shadows.dart' ;
109import 'package:sky/theme/colors.dart' as colors;
1110import 'package:sky/widgets/animated_component.dart' ;
@@ -30,14 +29,11 @@ import 'package:vector_math/vector_math.dart';
3029// The right nav can vary depending on content.
3130
3231const double _kWidth = 304.0 ;
33- const double _kMinFlingVelocity = 1.2 ;
32+ const double _kMinFlingVelocity = 365.0 ;
33+ const double _kFlingVelocityScale = 1.0 / 300.0 ;
3434const 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).
3835const Point _kOpenPosition = Point .origin;
3936const Point _kClosedPosition = const Point (- _kWidth, 0.0 );
40- const Curve _kAnimationCurve = linear;
4137
4238typedef void DrawerStatusChangeHandler (bool showing);
4339
@@ -69,7 +65,7 @@ class Drawer extends AnimatedComponent {
6965 AnimationPerformance _performance;
7066
7167 void initState () {
72- _position = new AnimatedType <Point >(_kClosedPosition, end: _kOpenPosition, curve : _kAnimationCurve );
68+ _position = new AnimatedType <Point >(_kClosedPosition, end: _kOpenPosition);
7369 _maskColor = new AnimatedColor (colors.transparent, end: const Color (0x7F000000 ));
7470 _performance = new AnimationPerformance ()
7571 ..duration = _kBaseSettleDuration
@@ -95,11 +91,18 @@ class Drawer extends AnimatedComponent {
9591 void _show () {
9692 if (navigator != null )
9793 navigator.pushState (this , (_) => _performance.reverse ());
98- _performance. play ( );
94+ _fling ( 1.0 );
9995 }
10096
10197 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);
103106 }
104107
105108 Widget build () {
@@ -151,9 +154,9 @@ class Drawer extends AnimatedComponent {
151154 DrawerStatus get _status => _performance.isDismissed ? DrawerStatus .inactive : DrawerStatus .active;
152155 bool get _isMostlyClosed => xPosition <= - _kWidth/ 2 ;
153156
154- void _settle () => _isMostlyClosed ? _performance. reverse () : _performance. play ( );
157+ void _settle () => _fling ( _isMostlyClosed ? - 1.0 : 1.0 );
155158
156- void handleMaskTap (_) => _performance. reverse ( );
159+ void handleMaskTap (_) => _fling ( - 1.0 );
157160
158161 // TODO(mpcomplete): Figure out how to generalize these handlers on a
159162 // "PannableThingy" interface.
@@ -176,8 +179,7 @@ class Drawer extends AnimatedComponent {
176179 }
177180
178181 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);
182184 }
183185}
0 commit comments