OLD | NEW |
1 part of widgets; | 1 part of widgets; |
2 | 2 |
3 const double _kWidth = 256.0; | 3 const double _kWidth = 256.0; |
4 const double _kMinFlingVelocity = 0.4; | 4 const double _kMinFlingVelocity = 0.4; |
5 const double _kBaseSettleDurationMS = 246.0; | 5 const double _kBaseSettleDurationMS = 246.0; |
6 const double _kMaxSettleDurationMS = 600.0; | 6 const double _kMaxSettleDurationMS = 600.0; |
7 const Cubic _kAnimationCurve = easeOut; | 7 const Cubic _kAnimationCurve = easeOut; |
8 | 8 |
9 class DrawerAnimation { | 9 class DrawerAnimation { |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 _animation = new AnimationGenerator(duration, begin: begin, end: end, | 66 _animation = new AnimationGenerator(duration, begin: begin, end: end, |
67 curve: curve); | 67 curve: curve); |
68 | 68 |
69 _animation.onTick.listen(_setPosition, onDone: () { | 69 _animation.onTick.listen(_setPosition, onDone: () { |
70 _animation = null; | 70 _animation = null; |
71 }); | 71 }); |
72 } | 72 } |
73 | 73 |
74 void _animateToPosition(double targetPosition) { | 74 void _animateToPosition(double targetPosition) { |
75 double distance = (targetPosition - _position).abs(); | 75 double distance = (targetPosition - _position).abs(); |
76 double targetDuration = distance / _kWidth * _kBaseSettleDurationMS; | 76 if (distance != 0) { |
77 double duration = math.min(targetDuration, _kMaxSettleDurationMS); | 77 double targetDuration = distance / _kWidth * _kBaseSettleDurationMS; |
78 _animate(duration, _position, targetPosition, _kAnimationCurve); | 78 double duration = math.min(targetDuration, _kMaxSettleDurationMS); |
| 79 _animate(duration, _position, targetPosition, _kAnimationCurve); |
| 80 } |
79 } | 81 } |
80 | 82 |
81 void handleFlingStart(event) { | 83 void handleFlingStart(event) { |
82 double direction = event.velocityX.sign; | 84 double direction = event.velocityX.sign; |
83 double velocityX = event.velocityX.abs() / 1000; | 85 double velocityX = event.velocityX.abs() / 1000; |
84 if (velocityX < _kMinFlingVelocity) | 86 if (velocityX < _kMinFlingVelocity) |
85 return; | 87 return; |
86 | 88 |
87 double targetPosition = direction < 0.0 ? -_kWidth : 0.0; | 89 double targetPosition = direction < 0.0 ? -_kWidth : 0.0; |
88 double distance = (targetPosition - _position).abs(); | 90 double distance = (targetPosition - _position).abs(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 style: _style, | 178 style: _style, |
177 inlineStyle: inlineStyle, | 179 inlineStyle: inlineStyle, |
178 children: [ mask, content ] | 180 children: [ mask, content ] |
179 )..events.listen('pointerdown', animation.handlePointerDown) | 181 )..events.listen('pointerdown', animation.handlePointerDown) |
180 ..events.listen('pointermove', animation.handlePointerMove) | 182 ..events.listen('pointermove', animation.handlePointerMove) |
181 ..events.listen('pointerup', animation.handlePointerUp) | 183 ..events.listen('pointerup', animation.handlePointerUp) |
182 ..events.listen('pointercancel', animation.handlePointerCancel); | 184 ..events.listen('pointercancel', animation.handlePointerCancel); |
183 | 185 |
184 } | 186 } |
185 } | 187 } |
OLD | NEW |