| 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:math' as math; | 5 import 'dart:math' as math; |
| 6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
| 7 | 7 |
| 8 import 'package:vector_math/vector_math.dart'; | 8 import 'package:vector_math/vector_math.dart'; |
| 9 | 9 |
| 10 import '../animation/animated_value.dart'; | 10 import '../animation/animated_value.dart'; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 void _checkValue() { | 47 void _checkValue() { |
| 48 var newClosedState = isClosed; | 48 var newClosedState = isClosed; |
| 49 if (onStatusChange != null && _oldClosedState != newClosedState) { | 49 if (onStatusChange != null && _oldClosedState != newClosedState) { |
| 50 onStatusChange(!newClosedState); | 50 onStatusChange(!newClosedState); |
| 51 _oldClosedState = newClosedState; | 51 _oldClosedState = newClosedState; |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 bool get isClosed => position.value == -_kWidth; | 55 bool get isClosed => position.value == -_kWidth; |
| 56 bool get _isMostlyClosed => position.value <= -_kWidth / 2; | 56 bool get _isMostlyClosed => position.value <= -_kWidth / 2; |
| 57 void toggle() => _isMostlyClosed ? _open() : _close(); | 57 void toggle() => _isMostlyClosed ? open() : close(); |
| 58 | 58 |
| 59 void handleMaskTap(_) => _close(); | 59 void handleMaskTap(_) => close(); |
| 60 void handlePointerDown(_) => position.stop(); | 60 void handlePointerDown(_) => position.stop(); |
| 61 | 61 |
| 62 void handlePointerMove(sky.PointerEvent event) { | 62 void handlePointerMove(sky.PointerEvent event) { |
| 63 if (position.isAnimating) | 63 if (position.isAnimating) |
| 64 return; | 64 return; |
| 65 position.value = math.min(0.0, math.max(position.value + event.dx, -_kWidth)
); | 65 position.value = math.min(0.0, math.max(position.value + event.dx, -_kWidth)
); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void handlePointerUp(_) { | 68 void handlePointerUp(_) { |
| 69 if (!position.isAnimating) | 69 if (!position.isAnimating) |
| 70 _settle(); | 70 _settle(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void handlePointerCancel(_) { | 73 void handlePointerCancel(_) { |
| 74 if (!position.isAnimating) | 74 if (!position.isAnimating) |
| 75 _settle(); | 75 _settle(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void _open() => _animateToPosition(0.0); | 78 void open() => _animateToPosition(0.0); |
| 79 | 79 |
| 80 void _close() => _animateToPosition(-_kWidth); | 80 void close() => _animateToPosition(-_kWidth); |
| 81 | 81 |
| 82 void _settle() => _isMostlyClosed ? _close() : _open(); | 82 void _settle() => _isMostlyClosed ? close() : open(); |
| 83 | 83 |
| 84 void _animateToPosition(double targetPosition) { | 84 void _animateToPosition(double targetPosition) { |
| 85 double distance = (targetPosition - position.value).abs(); | 85 double distance = (targetPosition - position.value).abs(); |
| 86 if (distance != 0) { | 86 if (distance != 0) { |
| 87 double targetDuration = distance / _kWidth * _kBaseSettleDurationMS; | 87 double targetDuration = distance / _kWidth * _kBaseSettleDurationMS; |
| 88 double duration = math.min(targetDuration, _kMaxSettleDurationMS); | 88 double duration = math.min(targetDuration, _kMaxSettleDurationMS); |
| 89 position.animateTo(targetPosition, duration, curve: _kAnimationCurve); | 89 position.animateTo(targetPosition, duration, curve: _kAnimationCurve); |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 return new Listener( | 157 return new Listener( |
| 158 child: new Stack([ mask, content ]), | 158 child: new Stack([ mask, content ]), |
| 159 onPointerDown: controller.handlePointerDown, | 159 onPointerDown: controller.handlePointerDown, |
| 160 onPointerMove: controller.handlePointerMove, | 160 onPointerMove: controller.handlePointerMove, |
| 161 onPointerUp: controller.handlePointerUp, | 161 onPointerUp: controller.handlePointerUp, |
| 162 onPointerCancel: controller.handlePointerCancel | 162 onPointerCancel: controller.handlePointerCancel |
| 163 ); | 163 ); |
| 164 } | 164 } |
| 165 | 165 |
| 166 } | 166 } |
| OLD | NEW |