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

Side by Side Diff: sky/framework/components/drawer.dart

Issue 993033003: Move example fn widgets into sky/framework/components (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « sky/framework/components/checkbox.dart ('k') | sky/framework/components/drawer_header.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 part of widgets; 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
3 // found in the LICENSE file.
4
5 import '../animation/curves.dart';
6 import '../animation/generator.dart';
7 import '../fn.dart';
8 import '../theme/colors.dart';
9 import '../theme/shadows.dart';
10 import 'dart:async';
11 import 'dart:math' as math;
12 import 'dart:sky' as sky;
2 13
3 const double _kWidth = 256.0; 14 const double _kWidth = 256.0;
4 const double _kMinFlingVelocity = 0.4; 15 const double _kMinFlingVelocity = 0.4;
5 const double _kBaseSettleDurationMS = 246.0; 16 const double _kBaseSettleDurationMS = 246.0;
6 const double _kMaxSettleDurationMS = 600.0; 17 const double _kMaxSettleDurationMS = 600.0;
7 const Cubic _kAnimationCurve = easeOut; 18 const Cubic _kAnimationCurve = easeOut;
8 19
9 class DrawerAnimation extends Animation { 20 class DrawerAnimation extends Animation {
10
11 Stream<double> get onPositionChanged => onValueChanged; 21 Stream<double> get onPositionChanged => onValueChanged;
12 22
13 bool get _isMostlyClosed => value <= -_kWidth / 2; 23 bool get _isMostlyClosed => value <= -_kWidth / 2;
14 24
15 DrawerAnimation() { 25 DrawerAnimation() {
16 value = -_kWidth; 26 value = -_kWidth;
17 } 27 }
18 28
19 void toggle(_) => _isMostlyClosed ? _open() : _close(); 29 void toggle(_) => _isMostlyClosed ? _open() : _close();
20 30
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 70
61 double targetPosition = direction < 0.0 ? -_kWidth : 0.0; 71 double targetPosition = direction < 0.0 ? -_kWidth : 0.0;
62 double distance = (targetPosition - value).abs(); 72 double distance = (targetPosition - value).abs();
63 double duration = distance / velocityX; 73 double duration = distance / velocityX;
64 74
65 animateTo(targetPosition, duration, curve: linear); 75 animateTo(targetPosition, duration, curve: linear);
66 } 76 }
67 } 77 }
68 78
69 class Drawer extends Component { 79 class Drawer extends Component {
70 80 static final Style _style = new Style('''
71 static Style _style = new Style('''
72 position: absolute; 81 position: absolute;
73 z-index: 2; 82 z-index: 2;
74 top: 0; 83 top: 0;
75 left: 0; 84 left: 0;
76 bottom: 0; 85 bottom: 0;
77 right: 0; 86 right: 0;
78 box-shadpw: ${Shadow[3]};''' 87 box-shadpw: ${Shadow[3]};'''
79 ); 88 );
80 89
81 static Style _maskStyle = new Style(''' 90 static final Style _maskStyle = new Style('''
82 background-color: black; 91 background-color: black;
83 will-change: opacity; 92 will-change: opacity;
84 position: absolute; 93 position: absolute;
85 top: 0; 94 top: 0;
86 left: 0; 95 left: 0;
87 bottom: 0; 96 bottom: 0;
88 right: 0;''' 97 right: 0;'''
89 ); 98 );
90 99
91 static Style _contentStyle = new Style(''' 100 static final Style _contentStyle = new Style('''
92 background-color: ${Grey[50]}; 101 background-color: ${Grey[50]};
93 will-change: transform; 102 will-change: transform;
94 position: absolute; 103 position: absolute;
95 z-index: 3; 104 z-index: 3;
96 width: 256px; 105 width: 256px;
97 top: 0; 106 top: 0;
98 left: 0; 107 left: 0;
99 bottom: 0;''' 108 bottom: 0;'''
100 ); 109 );
101 110
102 DrawerAnimation animation; 111 DrawerAnimation animation;
103 List<Node> children; 112 List<Node> children;
104 113
105 Drawer({ 114 Drawer({
106 Object key, 115 Object key,
107 this.animation, 116 this.animation,
108 this.children 117 this.children
109 }) : super(key: key); 118 }) : super(key: key) {
119 events.listen('pointerdown', animation.handlePointerDown);
120 events.listen('pointermove', animation.handlePointerMove);
121 events.listen('pointerup', animation.handlePointerUp);
122 events.listen('pointercancel', animation.handlePointerCancel);
123 }
110 124
111 double _position = -_kWidth; 125 double _position = -_kWidth;
112 126
113 bool _listening = false; 127 bool _listening = false;
114 128
115 void _ensureListening() { 129 void _ensureListening() {
116 if (_listening) 130 if (_listening)
117 return; 131 return;
118 132
119 _listening = true; 133 _listening = true;
(...skipping 23 matching lines...) Expand all
143 key: 'Content', 157 key: 'Content',
144 style: _contentStyle, 158 style: _contentStyle,
145 inlineStyle: contentInlineStyle, 159 inlineStyle: contentInlineStyle,
146 children: children 160 children: children
147 ); 161 );
148 162
149 return new Container( 163 return new Container(
150 style: _style, 164 style: _style,
151 inlineStyle: inlineStyle, 165 inlineStyle: inlineStyle,
152 children: [ mask, content ] 166 children: [ mask, content ]
153 )..events.listen('pointerdown', animation.handlePointerDown) 167 );
154 ..events.listen('pointermove', animation.handlePointerMove)
155 ..events.listen('pointerup', animation.handlePointerUp)
156 ..events.listen('pointercancel', animation.handlePointerCancel);
157
158 } 168 }
159 } 169 }
OLDNEW
« no previous file with comments | « sky/framework/components/checkbox.dart ('k') | sky/framework/components/drawer_header.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698