| 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/theme/shadows.dart'; | 9 import 'package:sky/theme/shadows.dart'; |
| 10 import 'package:sky/widgets/animated_component.dart'; | 10 import 'package:sky/widgets/animated_component.dart'; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 void initState() { | 66 void initState() { |
| 67 _builder = new AnimationBuilder() | 67 _builder = new AnimationBuilder() |
| 68 ..position = new AnimatedType<Point>( | 68 ..position = new AnimatedType<Point>( |
| 69 new Point(-_kWidth, 0.0), end: Point.origin, curve: _kAnimationCurve); | 69 new Point(-_kWidth, 0.0), end: Point.origin, curve: _kAnimationCurve); |
| 70 _performance = _builder.createPerformance([_builder.position], | 70 _performance = _builder.createPerformance([_builder.position], |
| 71 duration: _kBaseSettleDuration) | 71 duration: _kBaseSettleDuration) |
| 72 ..addListener(_checkForStateChanged); | 72 ..addListener(_checkForStateChanged); |
| 73 watch(_performance); | 73 watch(_performance); |
| 74 if (showing) | 74 if (showing) |
| 75 _performance.play(); | 75 _show(); |
| 76 } |
| 77 |
| 78 void _show() { |
| 79 if (navigator != null) |
| 80 navigator.pushState(this, (_) => _performance.reverse()); |
| 81 _performance.play(); |
| 76 } | 82 } |
| 77 | 83 |
| 78 void syncFields(Drawer source) { | 84 void syncFields(Drawer source) { |
| 79 const String kDrawerRouteName = "[open drawer]"; | |
| 80 children = source.children; | 85 children = source.children; |
| 81 level = source.level; | 86 level = source.level; |
| 82 navigator = source.navigator; | 87 navigator = source.navigator; |
| 83 if (showing != source.showing) { | 88 if (showing != source.showing) { |
| 84 showing = source.showing; | 89 showing = source.showing; |
| 85 if (showing) { | 90 if (showing) { |
| 86 if (navigator != null) { | 91 _show(); |
| 87 navigator.pushState(kDrawerRouteName, (_) { | |
| 88 onStatusChanged(DrawerStatus.inactive); | |
| 89 }); | |
| 90 } | |
| 91 _performance.play(); | |
| 92 } else { | 92 } else { |
| 93 if (navigator != null && navigator.currentRoute.name == kDrawerRouteName
) | |
| 94 navigator.pop(); | |
| 95 _performance.reverse(); | 93 _performance.reverse(); |
| 96 } | 94 } |
| 97 } | 95 } |
| 98 onStatusChanged = source.onStatusChanged; | 96 onStatusChanged = source.onStatusChanged; |
| 99 super.syncFields(source); | 97 super.syncFields(source); |
| 100 } | 98 } |
| 101 | 99 |
| 102 // TODO(mpcomplete): the animation system should handle building, maybe? Or | 100 // TODO(mpcomplete): the animation system should handle building, maybe? Or |
| 103 // at least setting the transform. Figure out how this could work for things | 101 // at least setting the transform. Figure out how this could work for things |
| 104 // like fades, slides, rotates, pinch, etc. | 102 // like fades, slides, rotates, pinch, etc. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 129 onPointerCancel: handlePointerCancel, | 127 onPointerCancel: handlePointerCancel, |
| 130 onGestureFlingStart: handleFlingStart | 128 onGestureFlingStart: handleFlingStart |
| 131 ); | 129 ); |
| 132 } | 130 } |
| 133 | 131 |
| 134 double get xPosition => _builder.position.value.x; | 132 double get xPosition => _builder.position.value.x; |
| 135 | 133 |
| 136 DrawerStatus _lastStatus; | 134 DrawerStatus _lastStatus; |
| 137 void _checkForStateChanged() { | 135 void _checkForStateChanged() { |
| 138 DrawerStatus status = _status; | 136 DrawerStatus status = _status; |
| 139 if (_lastStatus != null && status != _lastStatus && onStatusChanged != null) | 137 if (_lastStatus != null && status != _lastStatus) { |
| 140 onStatusChanged(status); | 138 if (status == DrawerStatus.inactive && |
| 139 navigator != null && |
| 140 navigator.currentRoute.key == this) |
| 141 navigator.pop(); |
| 142 if (onStatusChanged != null) |
| 143 onStatusChanged(status); |
| 144 } |
| 141 _lastStatus = status; | 145 _lastStatus = status; |
| 142 } | 146 } |
| 143 | 147 |
| 144 DrawerStatus get _status => _performance.isDismissed ? DrawerStatus.inactive :
DrawerStatus.active; | 148 DrawerStatus get _status => _performance.isDismissed ? DrawerStatus.inactive :
DrawerStatus.active; |
| 145 bool get _isMostlyClosed => xPosition <= -_kWidth/2; | 149 bool get _isMostlyClosed => xPosition <= -_kWidth/2; |
| 146 | 150 |
| 147 void _settle() => _isMostlyClosed ? _performance.reverse() : _performance.play
(); | 151 void _settle() => _isMostlyClosed ? _performance.reverse() : _performance.play
(); |
| 148 | 152 |
| 149 void handleMaskTap(_) => _performance.reverse(); | 153 void handleMaskTap(_) => _performance.reverse(); |
| 150 | 154 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 167 if (!_performance.isAnimating) | 171 if (!_performance.isAnimating) |
| 168 _settle(); | 172 _settle(); |
| 169 } | 173 } |
| 170 | 174 |
| 171 void handleFlingStart(event) { | 175 void handleFlingStart(event) { |
| 172 double velocityX = event.velocityX / 1000; | 176 double velocityX = event.velocityX / 1000; |
| 173 if (velocityX.abs() >= _kMinFlingVelocity) | 177 if (velocityX.abs() >= _kMinFlingVelocity) |
| 174 _performance.fling(velocity: velocityX / _kWidth); | 178 _performance.fling(velocity: velocityX / _kWidth); |
| 175 } | 179 } |
| 176 } | 180 } |
| OLD | NEW |