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

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

Issue 1027633003: [Effen] Add AnimatedComponent base class (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: cr changes 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/input.dart ('k') | sky/framework/components/popup_menu_item.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 // 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 '../fn.dart'; 7 import '../fn.dart';
7 import '../theme/colors.dart'; 8 import '../theme/colors.dart';
8 import '../theme/view-configuration.dart'; 9 import '../theme/view-configuration.dart';
9 import 'dart:math' as math; 10 import 'dart:math' as math;
10 import 'dart:sky' as sky; 11 import 'dart:sky' as sky;
11 import 'material.dart'; 12 import 'material.dart';
12 import 'popup_menu_item.dart'; 13 import 'popup_menu_item.dart';
13 14
14 const double _kItemFadeDuration = 300.0; 15 const double _kItemFadeDuration = 300.0;
(...skipping 10 matching lines...) Expand all
25 } 26 }
26 27
27 void close() { 28 void close() {
28 position.animateTo(0.0, _kMenuExpandDuration); 29 position.animateTo(0.0, _kMenuExpandDuration);
29 // TODO(abarth): We shouldn't mark the menu as closed until the animation 30 // TODO(abarth): We shouldn't mark the menu as closed until the animation
30 // completes. 31 // completes.
31 isOpen = false; 32 isOpen = false;
32 } 33 }
33 } 34 }
34 35
35 class PopupMenu extends Component { 36 class PopupMenu extends AnimatedComponent {
36 static final Style _style = new Style(''' 37 static final Style _style = new Style('''
37 border-radius: 2px; 38 border-radius: 2px;
38 padding: 8px 0; 39 padding: 8px 0;
39 background-color: ${Grey[50]};''' 40 background-color: ${Grey[50]};'''
40 ); 41 );
41 42
42 List<List<Node>> items; 43 List<List<Node>> items;
43 int level; 44 int level;
44 PopupMenuController controller; 45 PopupMenuController controller;
45 46
46 AnimatedValueListener _position; 47 double _position;
47 List<AnimatedValue> _opacities; 48 List<AnimatedValue> _opacities;
48 int _width; 49 int _width;
49 int _height; 50 int _height;
50 51
51 PopupMenu({ Object key, this.controller, this.items, this.level }) 52 PopupMenu({ Object key, this.controller, this.items, this.level })
52 : super(key: key) { 53 : super(key: key) {
53 _position = new AnimatedValueListener(this, controller.position); 54 animateField(controller.position, #_position);
55
56 onDidMount(_measureSize);
54 } 57 }
55 58
56 void _ensureItemAnimations() { 59 void _ensureItemAnimations() {
57 if (_opacities != null && controller.isOpen) 60 if (_opacities != null && controller.isOpen)
58 return; 61 return;
59 _opacities = new List.from(items.map((_) => new AnimatedValue(0.0))); 62 _opacities = new List.from(items.map((_) => new AnimatedValue(0.0)));
60 int i = 0; 63 int i = 0;
61 _opacities.forEach((opacity) { 64 _opacities.forEach((opacity) {
62 opacity.animateTo(1.0, _kItemFadeDuration, 65 opacity.animateTo(1.0, _kItemFadeDuration,
63 initialDelay: _kItemFadeDelay * ++i); 66 initialDelay: _kItemFadeDelay * ++i);
64 }); 67 });
65 } 68 }
66 69
67 String _inlineStyle() { 70 String _inlineStyle() {
68 double value = _position.value; 71 if (_position == null || _position == 1.0 || _height == null || _width == nu ll)
69 if (value == null || value == 1.0 || _height == null || _width == null)
70 return null; 72 return null;
71 return ''' 73 return '''
72 opacity: ${math.min(1.0, value * 1.5)}; 74 opacity: ${math.min(1.0, _position * 1.5)};
73 width: ${math.min(_width, _width * value * 3.0)}px; 75 width: ${math.min(_width, _width * _position * 3.0)}px;
74 height: ${_height * value}px;'''; 76 height: ${_height * _position}px;''';
75 } 77 }
76 78
77 void didMount() { 79 void _measureSize() {
78 setState(() { 80 setState(() {
79 var root = getRoot(); 81 var root = getRoot();
80 _width = root.clientWidth; 82 _width = root.clientWidth;
81 _height = root.clientHeight; 83 _height = root.clientHeight;
82 }); 84 });
83 } 85 }
84 86
85 void didUnmount() {
86 _position.stopListening();
87 }
88
89 Node build() { 87 Node build() {
90 _position.ensureListening();
91 _ensureItemAnimations(); 88 _ensureItemAnimations();
92 89
93 List<Node> children = []; 90 List<Node> children = [];
94 91
95 if (controller.isOpen) { 92 if (controller.isOpen) {
96 int i = 0; 93 int i = 0;
97 items.forEach((List<Node> item) { 94 items.forEach((List<Node> item) {
98 children.add( 95 children.add(
99 new PopupMenuItem(key: i, children: item, opacity: _opacities[i])); 96 new PopupMenuItem(key: i, children: item, opacity: _opacities[i]));
100 ++i; 97 ++i;
101 }); 98 });
102 } 99 }
103 100
104 return new Material( 101 return new Material(
105 style: _style, 102 style: _style,
106 inlineStyle: _inlineStyle(), 103 inlineStyle: _inlineStyle(),
107 children: children, 104 children: children,
108 level: level 105 level: level
109 ); 106 );
110 } 107 }
111 } 108 }
OLDNEW
« no previous file with comments | « sky/framework/components/input.dart ('k') | sky/framework/components/popup_menu_item.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698