| 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 'animated_component.dart'; |
| 5 import '../animation/animated_value.dart'; | 6 import '../animation/animated_value.dart'; |
| 6 import '../animation/curves.dart'; | 7 import '../animation/curves.dart'; |
| 7 import '../fn.dart'; | 8 import '../fn.dart'; |
| 8 import '../theme/colors.dart'; | 9 import '../theme/colors.dart'; |
| 9 import '../theme/shadows.dart'; | 10 import '../theme/shadows.dart'; |
| 10 import 'dart:async'; | 11 import 'dart:async'; |
| 11 import 'dart:math' as math; | 12 import 'dart:math' as math; |
| 12 import 'dart:sky' as sky; | 13 import 'dart:sky' as sky; |
| 13 import 'material.dart'; | 14 import 'material.dart'; |
| 14 | 15 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 return; | 68 return; |
| 68 | 69 |
| 69 double targetPosition = direction < 0.0 ? -_kWidth : 0.0; | 70 double targetPosition = direction < 0.0 ? -_kWidth : 0.0; |
| 70 double distance = (targetPosition - position.value).abs(); | 71 double distance = (targetPosition - position.value).abs(); |
| 71 double duration = distance / velocityX; | 72 double duration = distance / velocityX; |
| 72 | 73 |
| 73 position.animateTo(targetPosition, duration, curve: linear); | 74 position.animateTo(targetPosition, duration, curve: linear); |
| 74 } | 75 } |
| 75 } | 76 } |
| 76 | 77 |
| 77 class Drawer extends Component { | 78 class Drawer extends AnimatedComponent { |
| 78 static final Style _style = new Style(''' | 79 static final Style _style = new Style(''' |
| 79 position: absolute; | 80 position: absolute; |
| 80 top: 0; | 81 top: 0; |
| 81 left: 0; | 82 left: 0; |
| 82 bottom: 0; | 83 bottom: 0; |
| 83 right: 0;''' | 84 right: 0;''' |
| 84 ); | 85 ); |
| 85 | 86 |
| 86 static final Style _maskStyle = new Style(''' | 87 static final Style _maskStyle = new Style(''' |
| 87 background-color: black; | 88 background-color: black; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 100 width: ${_kWidth}px; | 101 width: ${_kWidth}px; |
| 101 top: 0; | 102 top: 0; |
| 102 left: 0; | 103 left: 0; |
| 103 bottom: 0;''' | 104 bottom: 0;''' |
| 104 ); | 105 ); |
| 105 | 106 |
| 106 List<Node> children; | 107 List<Node> children; |
| 107 int level; | 108 int level; |
| 108 DrawerController controller; | 109 DrawerController controller; |
| 109 | 110 |
| 110 AnimatedValueListener _position; | 111 double _position; |
| 111 | 112 |
| 112 Drawer({ | 113 Drawer({ |
| 113 Object key, | 114 Object key, |
| 114 this.controller, | 115 this.controller, |
| 115 this.children, | 116 this.children, |
| 116 this.level: 0 | 117 this.level: 0 |
| 117 }) : super(key: key) { | 118 }) : super(key: key) { |
| 118 _position = new AnimatedValueListener(this, controller.position); | 119 animateField(controller.position, #_position); |
| 119 } | |
| 120 | |
| 121 void didUnmount() { | |
| 122 _position.stopListening(); | |
| 123 } | 120 } |
| 124 | 121 |
| 125 Node build() { | 122 Node build() { |
| 126 _position.ensureListening(); | 123 bool isClosed = _position <= -_kWidth; |
| 127 | |
| 128 bool isClosed = _position.value <= -_kWidth; | |
| 129 String inlineStyle = 'display: ${isClosed ? 'none' : ''}'; | 124 String inlineStyle = 'display: ${isClosed ? 'none' : ''}'; |
| 130 String maskInlineStyle = 'opacity: ${(_position.value / _kWidth + 1) * 0.5}'
; | 125 String maskInlineStyle = 'opacity: ${(_position / _kWidth + 1) * 0.5}'; |
| 131 String contentInlineStyle = 'transform: translateX(${_position.value}px)'; | 126 String contentInlineStyle = 'transform: translateX(${_position}px)'; |
| 132 | 127 |
| 133 var mask = new EventTarget( | 128 var mask = new EventTarget( |
| 134 new Container( | 129 new Container( |
| 135 key: 'Mask', | 130 key: 'Mask', |
| 136 style: _maskStyle, | 131 style: _maskStyle, |
| 137 inlineStyle: maskInlineStyle | 132 inlineStyle: maskInlineStyle |
| 138 ), | 133 ), |
| 139 onGestureTap: controller.handleMaskTap, | 134 onGestureTap: controller.handleMaskTap, |
| 140 onGestureFlingStart: controller.handleFlingStart | 135 onGestureFlingStart: controller.handleFlingStart |
| 141 ); | 136 ); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 154 inlineStyle: inlineStyle, | 149 inlineStyle: inlineStyle, |
| 155 children: [ mask, content ] | 150 children: [ mask, content ] |
| 156 ), | 151 ), |
| 157 onPointerDown: controller.handlePointerDown, | 152 onPointerDown: controller.handlePointerDown, |
| 158 onPointerMove: controller.handlePointerMove, | 153 onPointerMove: controller.handlePointerMove, |
| 159 onPointerUp: controller.handlePointerUp, | 154 onPointerUp: controller.handlePointerUp, |
| 160 onPointerCancel: controller.handlePointerCancel | 155 onPointerCancel: controller.handlePointerCancel |
| 161 ); | 156 ); |
| 162 } | 157 } |
| 163 } | 158 } |
| OLD | NEW |