| 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 '../animation/animation.dart'; | 5 import '../animation/animation.dart'; |
| 6 import '../animation/curves.dart'; | 6 import '../animation/curves.dart'; |
| 7 import '../fn.dart'; | 7 import '../fn.dart'; |
| 8 import '../theme/colors.dart'; | 8 import '../theme/colors.dart'; |
| 9 import '../theme/shadows.dart'; | 9 import '../theme/shadows.dart'; |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| 11 import 'dart:math' as math; | 11 import 'dart:math' as math; |
| 12 import 'dart:sky' as sky; | 12 import 'dart:sky' as sky; |
| 13 import 'material.dart'; | 13 import 'material.dart'; |
| 14 | 14 |
| 15 const double _kWidth = 256.0; | 15 const double _kWidth = 304.0; |
| 16 const double _kMinFlingVelocity = 0.4; | 16 const double _kMinFlingVelocity = 0.4; |
| 17 const double _kBaseSettleDurationMS = 246.0; | 17 const double _kBaseSettleDurationMS = 246.0; |
| 18 const double _kMaxSettleDurationMS = 600.0; | 18 const double _kMaxSettleDurationMS = 600.0; |
| 19 const Cubic _kAnimationCurve = easeOut; | 19 const Cubic _kAnimationCurve = parabolicRise; |
| 20 | 20 |
| 21 class DrawerAnimation extends Animation { | 21 class DrawerAnimation extends Animation { |
| 22 Stream<double> get onPositionChanged => onValueChanged; | 22 Stream<double> get onPositionChanged => onValueChanged; |
| 23 | 23 |
| 24 bool get _isMostlyClosed => value <= -_kWidth / 2; | 24 bool get _isMostlyClosed => value <= -_kWidth / 2; |
| 25 | 25 |
| 26 DrawerAnimation() { | 26 DrawerAnimation() { |
| 27 value = -_kWidth; | 27 value = -_kWidth; |
| 28 } | 28 } |
| 29 | 29 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 double distance = (targetPosition - value).abs(); | 73 double distance = (targetPosition - value).abs(); |
| 74 double duration = distance / velocityX; | 74 double duration = distance / velocityX; |
| 75 | 75 |
| 76 animateTo(targetPosition, duration, curve: linear); | 76 animateTo(targetPosition, duration, curve: linear); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 class Drawer extends Component { | 80 class Drawer extends Component { |
| 81 static final Style _style = new Style(''' | 81 static final Style _style = new Style(''' |
| 82 position: absolute; | 82 position: absolute; |
| 83 z-index: 2; | |
| 84 top: 0; | 83 top: 0; |
| 85 left: 0; | 84 left: 0; |
| 86 bottom: 0; | 85 bottom: 0; |
| 87 right: 0;''' | 86 right: 0;''' |
| 88 ); | 87 ); |
| 89 | 88 |
| 90 static final Style _maskStyle = new Style(''' | 89 static final Style _maskStyle = new Style(''' |
| 91 background-color: black; | 90 background-color: black; |
| 92 will-change: opacity; | 91 will-change: opacity; |
| 93 position: absolute; | 92 position: absolute; |
| 94 top: 0; | 93 top: 0; |
| 95 left: 0; | 94 left: 0; |
| 96 bottom: 0; | 95 bottom: 0; |
| 97 right: 0;''' | 96 right: 0;''' |
| 98 ); | 97 ); |
| 99 | 98 |
| 100 static final Style _contentStyle = new Style(''' | 99 static final Style _contentStyle = new Style(''' |
| 101 background-color: ${Grey[50]}; | 100 background-color: ${Grey[50]}; |
| 102 will-change: transform; | 101 will-change: transform; |
| 103 position: absolute; | 102 position: absolute; |
| 104 z-index: 3; | 103 width: 304px; |
| 105 width: 256px; | |
| 106 top: 0; | 104 top: 0; |
| 107 left: 0; | 105 left: 0; |
| 108 bottom: 0;''' | 106 bottom: 0;''' |
| 109 ); | 107 ); |
| 110 | 108 |
| 111 DrawerAnimation animation; | 109 DrawerAnimation animation; |
| 112 List<Node> children; | 110 List<Node> children; |
| 113 int level; | 111 int level; |
| 114 | 112 |
| 115 Drawer({ | 113 Drawer({ |
| (...skipping 22 matching lines...) Expand all Loading... |
| 138 _position = position; | 136 _position = position; |
| 139 }); | 137 }); |
| 140 }); | 138 }); |
| 141 } | 139 } |
| 142 | 140 |
| 143 Node build() { | 141 Node build() { |
| 144 _ensureListening(); | 142 _ensureListening(); |
| 145 | 143 |
| 146 bool isClosed = _position <= -_kWidth; | 144 bool isClosed = _position <= -_kWidth; |
| 147 String inlineStyle = 'display: ${isClosed ? 'none' : ''}'; | 145 String inlineStyle = 'display: ${isClosed ? 'none' : ''}'; |
| 148 String maskInlineStyle = 'opacity: ${(_position / _kWidth + 1) * 0.25}'; | 146 String maskInlineStyle = 'opacity: ${(_position / _kWidth + 1) * 0.5}'; |
| 149 String contentInlineStyle = 'transform: translateX(${_position}px)'; | 147 String contentInlineStyle = 'transform: translateX(${_position}px)'; |
| 150 | 148 |
| 151 Container mask = new Container( | 149 Container mask = new Container( |
| 152 key: 'Mask', | 150 key: 'Mask', |
| 153 style: _maskStyle, | 151 style: _maskStyle, |
| 154 inlineStyle: maskInlineStyle | 152 inlineStyle: maskInlineStyle |
| 155 )..events.listen('gesturetap', animation.handleMaskTap) | 153 )..events.listen('gesturetap', animation.handleMaskTap) |
| 156 ..events.listen('gestureflingstart', animation.handleFlingStart); | 154 ..events.listen('gestureflingstart', animation.handleFlingStart); |
| 157 | 155 |
| 158 Material content = new Material( | 156 Material content = new Material( |
| 159 key: 'Content', | 157 key: 'Content', |
| 160 style: _contentStyle, | 158 style: _contentStyle, |
| 161 inlineStyle: contentInlineStyle, | 159 inlineStyle: contentInlineStyle, |
| 162 children: children, | 160 children: children, |
| 163 level: level | 161 level: level |
| 164 ); | 162 ); |
| 165 | 163 |
| 166 return new Container( | 164 return new Container( |
| 167 style: _style, | 165 style: _style, |
| 168 inlineStyle: inlineStyle, | 166 inlineStyle: inlineStyle, |
| 169 children: [ mask, content ] | 167 children: [ mask, content ] |
| 170 ); | 168 ); |
| 171 } | 169 } |
| 172 } | 170 } |
| OLD | NEW |