| 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/curves.dart'; | 5 import '../animation/curves.dart'; |
| 6 import '../animation/generator.dart'; | 6 import '../animation/generator.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 | 14 |
| 14 const double _kWidth = 256.0; | 15 const double _kWidth = 256.0; |
| 15 const double _kMinFlingVelocity = 0.4; | 16 const double _kMinFlingVelocity = 0.4; |
| 16 const double _kBaseSettleDurationMS = 246.0; | 17 const double _kBaseSettleDurationMS = 246.0; |
| 17 const double _kMaxSettleDurationMS = 600.0; | 18 const double _kMaxSettleDurationMS = 600.0; |
| 18 const Cubic _kAnimationCurve = easeOut; | 19 const Cubic _kAnimationCurve = easeOut; |
| 19 | 20 |
| 20 class DrawerAnimation extends Animation { | 21 class DrawerAnimation extends Animation { |
| 21 Stream<double> get onPositionChanged => onValueChanged; | 22 Stream<double> get onPositionChanged => onValueChanged; |
| 22 | 23 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 | 79 |
| 79 class Drawer extends Component { | 80 class Drawer extends Component { |
| 80 static final Style _style = new Style(''' | 81 static final Style _style = new Style(''' |
| 81 position: absolute; | 82 position: absolute; |
| 82 z-index: 2; | 83 z-index: 2; |
| 83 top: 0; | 84 top: 0; |
| 84 left: 0; | 85 left: 0; |
| 85 bottom: 0; | 86 bottom: 0; |
| 86 right: 0; | 87 right: 0;''' |
| 87 box-shadpw: ${Shadow[3]};''' | |
| 88 ); | 88 ); |
| 89 | 89 |
| 90 static final Style _maskStyle = new Style(''' | 90 static final Style _maskStyle = new Style(''' |
| 91 background-color: black; | 91 background-color: black; |
| 92 will-change: opacity; | 92 will-change: opacity; |
| 93 position: absolute; | 93 position: absolute; |
| 94 top: 0; | 94 top: 0; |
| 95 left: 0; | 95 left: 0; |
| 96 bottom: 0; | 96 bottom: 0; |
| 97 right: 0;''' | 97 right: 0;''' |
| 98 ); | 98 ); |
| 99 | 99 |
| 100 static final Style _contentStyle = new Style(''' | 100 static final Style _contentStyle = new Style(''' |
| 101 background-color: ${Grey[50]}; | 101 background-color: ${Grey[50]}; |
| 102 will-change: transform; | 102 will-change: transform; |
| 103 position: absolute; | 103 position: absolute; |
| 104 z-index: 3; | 104 z-index: 3; |
| 105 width: 256px; | 105 width: 256px; |
| 106 top: 0; | 106 top: 0; |
| 107 left: 0; | 107 left: 0; |
| 108 bottom: 0;''' | 108 bottom: 0;''' |
| 109 ); | 109 ); |
| 110 | 110 |
| 111 DrawerAnimation animation; | 111 DrawerAnimation animation; |
| 112 List<Node> children; | 112 List<Node> children; |
| 113 int level; |
| 113 | 114 |
| 114 Drawer({ | 115 Drawer({ |
| 115 Object key, | 116 Object key, |
| 116 this.animation, | 117 this.animation, |
| 117 this.children | 118 this.children, |
| 119 this.level: 0 |
| 118 }) : super(key: key) { | 120 }) : super(key: key) { |
| 119 events.listen('pointerdown', animation.handlePointerDown); | 121 events.listen('pointerdown', animation.handlePointerDown); |
| 120 events.listen('pointermove', animation.handlePointerMove); | 122 events.listen('pointermove', animation.handlePointerMove); |
| 121 events.listen('pointerup', animation.handlePointerUp); | 123 events.listen('pointerup', animation.handlePointerUp); |
| 122 events.listen('pointercancel', animation.handlePointerCancel); | 124 events.listen('pointercancel', animation.handlePointerCancel); |
| 123 } | 125 } |
| 124 | 126 |
| 125 double _position = -_kWidth; | 127 double _position = -_kWidth; |
| 126 | 128 |
| 127 bool _listening = false; | 129 bool _listening = false; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 141 Node build() { | 143 Node build() { |
| 142 _ensureListening(); | 144 _ensureListening(); |
| 143 | 145 |
| 144 bool isClosed = _position <= -_kWidth; | 146 bool isClosed = _position <= -_kWidth; |
| 145 String inlineStyle = 'display: ${isClosed ? 'none' : ''}'; | 147 String inlineStyle = 'display: ${isClosed ? 'none' : ''}'; |
| 146 String maskInlineStyle = 'opacity: ${(_position / _kWidth + 1) * 0.25}'; | 148 String maskInlineStyle = 'opacity: ${(_position / _kWidth + 1) * 0.25}'; |
| 147 String contentInlineStyle = 'transform: translateX(${_position}px)'; | 149 String contentInlineStyle = 'transform: translateX(${_position}px)'; |
| 148 | 150 |
| 149 Container mask = new Container( | 151 Container mask = new Container( |
| 150 key: 'Mask', | 152 key: 'Mask', |
| 151 style: _maskStyle, | 153 styles: [_maskStyle], |
| 152 inlineStyle: maskInlineStyle | 154 inlineStyle: maskInlineStyle |
| 153 )..events.listen('gesturetap', animation.handleMaskTap) | 155 )..events.listen('gesturetap', animation.handleMaskTap) |
| 154 ..events.listen('gestureflingstart', animation.handleFlingStart); | 156 ..events.listen('gestureflingstart', animation.handleFlingStart); |
| 155 | 157 |
| 156 Container content = new Container( | 158 Material content = new Material( |
| 157 key: 'Content', | 159 key: 'Content', |
| 158 style: _contentStyle, | 160 styles: [_contentStyle], |
| 159 inlineStyle: contentInlineStyle, | 161 inlineStyle: contentInlineStyle, |
| 160 children: children | 162 children: children, |
| 163 level: level |
| 161 ); | 164 ); |
| 162 | 165 |
| 163 return new Container( | 166 return new Container( |
| 164 style: _style, | 167 styles: [_style], |
| 165 inlineStyle: inlineStyle, | 168 inlineStyle: inlineStyle, |
| 166 children: [ mask, content ] | 169 children: [ mask, content ] |
| 167 ); | 170 ); |
| 168 } | 171 } |
| 169 } | 172 } |
| OLD | NEW |