Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: sky/sdk/lib/framework/components2/drawer.dart

Issue 1147143005: Make Drawer in components2 work (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: fix margin Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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';
6 import '../animation/animated_value.dart'; 5 import '../animation/animated_value.dart';
7 import '../animation/curves.dart'; 6 import '../animation/curves.dart';
8 import '../fn2.dart'; 7 import '../fn2.dart';
8 import '../rendering/box.dart';
9 import '../theme/colors.dart'; 9 import '../theme/colors.dart';
10 import 'animated_component.dart';
10 import 'dart:math' as math; 11 import 'dart:math' as math;
11 import 'dart:sky' as sky; 12 import 'dart:sky' as sky;
12 import 'material.dart'; 13 import 'material.dart';
14 import 'package:vector_math/vector_math.dart';
13 15
14 const double _kWidth = 304.0; 16 const double _kWidth = 304.0;
15 const double _kMinFlingVelocity = 0.4; 17 const double _kMinFlingVelocity = 0.4;
16 const double _kBaseSettleDurationMS = 246.0; 18 const double _kBaseSettleDurationMS = 246.0;
17 const double _kMaxSettleDurationMS = 600.0; 19 const double _kMaxSettleDurationMS = 600.0;
18 const Curve _kAnimationCurve = parabolicRise; 20 const Curve _kAnimationCurve = parabolicRise;
19 21
20 typedef void DrawerStatusChangeHandler (bool showing); 22 typedef void DrawerStatusChangeHandler (bool showing);
21 23
22 class DrawerController { 24 class DrawerController {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 double targetPosition = direction < 0.0 ? -_kWidth : 0.0; 85 double targetPosition = direction < 0.0 ? -_kWidth : 0.0;
84 double distance = (targetPosition - position.value).abs(); 86 double distance = (targetPosition - position.value).abs();
85 double duration = distance / velocityX; 87 double duration = distance / velocityX;
86 88
87 if (distance > 0) 89 if (distance > 0)
88 position.animateTo(targetPosition, duration, curve: linear); 90 position.animateTo(targetPosition, duration, curve: linear);
89 } 91 }
90 } 92 }
91 93
92 class Drawer extends AnimatedComponent { 94 class Drawer extends AnimatedComponent {
93 // TODO(abarth): We need a better way to become a container for absolutely
94 // positioned elements.
95 static final Style _style = new Style('''
96 transform: translateX(0);''');
97
98 static final Style _maskStyle = new Style('''
99 background-color: black;
100 will-change: opacity;'''
101 );
102
103 static final Style _contentStyle = new Style('''
104 background-color: ${Grey[50]};
105 will-change: transform;
106 width: ${_kWidth}px;'''
107 );
108
109 List<UINode> children; 95 List<UINode> children;
110 int level; 96 int level;
111 DrawerController controller; 97 DrawerController controller;
112 98
113 double _position; 99 double _position;
114 100
115 Drawer({ 101 Drawer({
116 Object key, 102 Object key,
117 this.controller, 103 this.controller,
118 this.children, 104 this.children,
119 this.level: 0 105 this.level: 0
120 }) : super(key: key) { 106 }) : super(key: key) {
121 animateField(controller.position, #_position); 107 animateField(controller.position, #_position);
122 } 108 }
123 109
124 UINode build() { 110 UINode build() {
125 String maskInlineStyle = 'opacity: ${(_position / _kWidth + 1) * 0.5}'; 111 Matrix4 transform = new Matrix4.identity();
126 String contentInlineStyle = 'transform: translateX(${_position}px)'; 112 transform.translate(_position);
113
114 int maskColor = ((_position / _kWidth + 1) * 0xFF).floor() << 24;
127 115
128 var mask = new EventListenerNode( 116 var mask = new EventListenerNode(
129 new Container( 117 new Container(
130 style: _maskStyle, 118 desiredSize: new sky.Size.infinite(),
131 inlineStyle: maskInlineStyle 119 decoration: new BoxDecoration(backgroundColor: maskColor)
Hixie 2015/06/03 21:39:56 this will need fixing with the new api for color
132 ), 120 ),
133 onGestureTap: controller.handleMaskTap, 121 onGestureTap: controller.handleMaskTap,
134 onGestureFlingStart: controller.handleFlingStart 122 onGestureFlingStart: controller.handleFlingStart
135 ); 123 );
136 124
137 Material content = new Material( 125 Material content = new Material(
138 content: new Container( 126 content: new Container(
139 style: _contentStyle, 127 decoration: new BoxDecoration(backgroundColor: 0xFFFFFFFF),
140 inlineStyle: contentInlineStyle, 128 desiredSize: new sky.Size(_kWidth, double.INFINITY),
Hixie 2015/06/03 21:39:56 sky.Size.onlyWidth?
141 children: children 129 transform: transform,
130 child: new BlockContainer(children: children)
142 ), 131 ),
143 level: level); 132 level: level);
144 133
145 return new EventListenerNode( 134 return new EventListenerNode(
146 new FillStackContainer( 135 new StackContainer(
147 style: _style,
148 children: [ mask, content ] 136 children: [ mask, content ]
149 ), 137 ),
150 onPointerDown: controller.handlePointerDown, 138 onPointerDown: controller.handlePointerDown,
151 onPointerMove: controller.handlePointerMove, 139 onPointerMove: controller.handlePointerMove,
152 onPointerUp: controller.handlePointerUp, 140 onPointerUp: controller.handlePointerUp,
153 onPointerCancel: controller.handlePointerCancel 141 onPointerCancel: controller.handlePointerCancel
154 ); 142 );
155 } 143 }
156 } 144 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698