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 _kMinAnimationDurationMS = 246.0; | 5 const double _kMinAnimationDurationMS = 246.0; |
6 const double _kMaxAnimationDurationMS = 600.0; | 6 const double _kMaxAnimationDurationMS = 600.0; |
7 const Cubic _kAnimationCurve = easeOut; | 7 const Cubic _kAnimationCurve = easeOut; |
8 | 8 |
9 class DrawerAnimation { | 9 class DrawerAnimation { |
10 | 10 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 background-color: #FAFAFA; | 120 background-color: #FAFAFA; |
121 will-change: transform; | 121 will-change: transform; |
122 position: absolute; | 122 position: absolute; |
123 z-index: 3; | 123 z-index: 3; |
124 width: 256px; | 124 width: 256px; |
125 top: 0; | 125 top: 0; |
126 left: 0; | 126 left: 0; |
127 bottom: 0;''' | 127 bottom: 0;''' |
128 ); | 128 ); |
129 | 129 |
130 Stream<double> onPositionChanged; | 130 DrawerAnimation animation; |
131 sky.EventListener handleMaskFling; | |
132 sky.EventListener handleMaskTap; | |
133 sky.EventListener handlePointerCancel; | |
134 sky.EventListener handlePointerDown; | |
135 sky.EventListener handlePointerMove; | |
136 sky.EventListener handlePointerUp; | |
137 List<Node> children; | 131 List<Node> children; |
138 | 132 |
139 Drawer({ | 133 Drawer({ |
140 Object key, | 134 Object key, |
141 this.onPositionChanged, | 135 this.animation, |
142 this.handleMaskFling, | |
143 this.handleMaskTap, | |
144 this.handlePointerCancel, | |
145 this.handlePointerDown, | |
146 this.handlePointerMove, | |
147 this.handlePointerUp, | |
148 this.children | 136 this.children |
149 }) : super(key: key); | 137 }) : super(key: key); |
150 | 138 |
151 double _position = -_kWidth; | 139 double _position = -_kWidth; |
152 | 140 |
153 bool _listening = false; | 141 bool _listening = false; |
154 | 142 |
155 void _ensureListening() { | 143 void _ensureListening() { |
156 if (_listening) | 144 if (_listening) |
157 return; | 145 return; |
158 | 146 |
159 _listening = true; | 147 _listening = true; |
160 onPositionChanged.listen((position) { | 148 animation.onPositionChanged.listen((position) { |
161 setState(() { | 149 setState(() { |
162 _position = position; | 150 _position = position; |
163 }); | 151 }); |
164 }); | 152 }); |
165 } | 153 } |
166 | 154 |
167 Node render() { | 155 Node render() { |
168 _ensureListening(); | 156 _ensureListening(); |
169 | 157 |
170 bool isClosed = _position <= -_kWidth; | 158 bool isClosed = _position <= -_kWidth; |
171 String inlineStyle = 'display: ${isClosed ? 'none' : ''}'; | 159 String inlineStyle = 'display: ${isClosed ? 'none' : ''}'; |
172 String maskInlineStyle = 'opacity: ${(_position / _kWidth + 1) * 0.25}'; | 160 String maskInlineStyle = 'opacity: ${(_position / _kWidth + 1) * 0.25}'; |
173 String contentInlineStyle = 'transform: translateX(${_position}px)'; | 161 String contentInlineStyle = 'transform: translateX(${_position}px)'; |
174 | 162 |
| 163 Container mask = new Container( |
| 164 key: 'Mask', |
| 165 style: _maskStyle, |
| 166 inlineStyle: maskInlineStyle |
| 167 )..events.listen('gesturetap', animation.handleMaskTap) |
| 168 ..events.listen('gestureflingstart', animation.handleFlingStart); |
| 169 |
| 170 Container content = new Container( |
| 171 key: 'Content', |
| 172 style: _contentStyle, |
| 173 inlineStyle: contentInlineStyle, |
| 174 children: children |
| 175 ); |
| 176 |
175 return new Container( | 177 return new Container( |
176 style: _style, | 178 style: _style, |
177 inlineStyle: inlineStyle, | 179 inlineStyle: inlineStyle, |
178 onPointerDown: handlePointerDown, | 180 children: [ mask, content ] |
179 onPointerMove: handlePointerMove, | 181 )..events.listen('pointerdown', animation.handlePointerDown) |
180 onPointerUp: handlePointerUp, | 182 ..events.listen('pointermove', animation.handlePointerMove) |
181 onPointerCancel: handlePointerCancel, | 183 ..events.listen('pointerup', animation.handlePointerUp) |
| 184 ..events.listen('pointercancel', animation.handlePointerCancel); |
182 | 185 |
183 children: [ | |
184 new Container( | |
185 key: 'Mask', | |
186 style: _maskStyle, | |
187 inlineStyle: maskInlineStyle, | |
188 onGestureTap: handleMaskTap, | |
189 onFlingStart: handleMaskFling | |
190 ), | |
191 new Container( | |
192 key: 'Content', | |
193 style: _contentStyle, | |
194 inlineStyle: contentInlineStyle, | |
195 children: children | |
196 ) | |
197 ] | |
198 ); | |
199 } | 186 } |
200 } | 187 } |
OLD | NEW |