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

Side by Side Diff: sky/examples/stocks-fn/lib/stock_app.dart

Issue 1019633004: Change how events are handled in Effen (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 | « no previous file | sky/framework/components/button_base.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 'package:sky/framework/components/action_bar.dart'; 5 import 'package:sky/framework/components/action_bar.dart';
6 import 'package:sky/framework/components/drawer.dart'; 6 import 'package:sky/framework/components/drawer.dart';
7 import 'package:sky/framework/components/drawer_header.dart'; 7 import 'package:sky/framework/components/drawer_header.dart';
8 import 'package:sky/framework/components/floating_action_button.dart'; 8 import 'package:sky/framework/components/floating_action_button.dart';
9 import 'package:sky/framework/components/icon.dart'; 9 import 'package:sky/framework/components/icon.dart';
10 import 'package:sky/framework/components/input.dart'; 10 import 'package:sky/framework/components/input.dart';
11 import 'package:sky/framework/components/menu_divider.dart'; 11 import 'package:sky/framework/components/menu_divider.dart';
12 import 'package:sky/framework/components/menu_item.dart'; 12 import 'package:sky/framework/components/menu_item.dart';
13 import 'package:sky/framework/components/popup_menu.dart'; 13 import 'package:sky/framework/components/popup_menu.dart';
14 import 'package:sky/framework/fn.dart'; 14 import 'package:sky/framework/fn.dart';
15 import 'package:sky/framework/theme/typography.dart' as typography; 15 import 'package:sky/framework/theme/typography.dart' as typography;
16 import 'stock_data.dart'; 16 import 'stock_data.dart';
17 import 'stock_list.dart'; 17 import 'stock_list.dart';
18 import 'stock_menu.dart'; 18 import 'stock_menu.dart';
19 19
20 class StocksApp extends App { 20 class StocksApp extends App {
21 21
22 DrawerController _drawerController = new DrawerController(); 22 DrawerController _drawerController = new DrawerController();
23 PopupMenuController _menuController = new PopupMenuController(); 23 PopupMenuController _menuController;
24 24
25 static Style _style = new Style(''' 25 static Style _style = new Style('''
26 display: flex; 26 display: flex;
27 flex-direction: column; 27 flex-direction: column;
28 height: -webkit-fill-available; 28 height: -webkit-fill-available;
29 ${typography.typeface}; 29 ${typography.typeface};
30 ${typography.black.body1};''' 30 ${typography.black.body1};'''
31 ); 31 );
32 32
33 static Style _iconStyle = new Style(''' 33 static Style _iconStyle = new Style('''
(...skipping 17 matching lines...) Expand all
51 } 51 }
52 52
53 void _handleSearchClick(_) { 53 void _handleSearchClick(_) {
54 setState(() { 54 setState(() {
55 _isSearching = !_isSearching; 55 _isSearching = !_isSearching;
56 }); 56 });
57 } 57 }
58 58
59 void _handleMenuClick(_) { 59 void _handleMenuClick(_) {
60 setState(() { 60 setState(() {
61 _menuController = new PopupMenuController();
61 _menuController.open(); 62 _menuController.open();
62 }); 63 });
63 } 64 }
64 65
65 void _handleSearchQueryChanged(query) { 66 void _handleSearchQueryChanged(query) {
66 setState(() { 67 setState(() {
67 _searchQuery = query; 68 _searchQuery = query;
68 }); 69 });
69 } 70 }
70 71
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 Node title; 105 Node title;
105 if (_isSearching) { 106 if (_isSearching) {
106 title = new Input(focused: true, placeholder: 'Search stocks', 107 title = new Input(focused: true, placeholder: 'Search stocks',
107 onChanged: _handleSearchQueryChanged); 108 onChanged: _handleSearchQueryChanged);
108 } else { 109 } else {
109 title = new Text('Stocks'); 110 title = new Text('Stocks');
110 } 111 }
111 112
112 var toolbar = new ActionBar( 113 var toolbar = new ActionBar(
113 children: [ 114 children: [
114 new Icon(key: 'menu', style: _iconStyle, 115 new EventTarget(
115 size: 24, 116 new Icon(key: 'menu', style: _iconStyle,
116 type: 'navigation/menu_white') 117 size: 24,
117 ..events.listen('gesturetap', _drawerController.toggle), 118 type: 'navigation/menu_white'),
119 onGestureTap: _drawerController.toggle
120 ),
118 new Container( 121 new Container(
119 style: _titleStyle, 122 style: _titleStyle,
120 children: [title] 123 children: [title]
121 ), 124 ),
122 new Icon(key: 'search', style: _iconStyle, 125 new EventTarget(
123 size: 24, 126 new Icon(key: 'search', style: _iconStyle,
124 type: 'action/search_white') 127 size: 24,
125 ..events.listen('gesturetap', _handleSearchClick), 128 type: 'action/search_white'),
126 new Icon(key: 'more_white', style: _iconStyle, 129 onGestureTap: _handleSearchClick
127 size: 24, 130 ),
128 type: 'navigation/more_vert_white') 131 new EventTarget(
129 ..events.listen('gesturetap', _handleMenuClick), 132 new Icon(key: 'more_white', style: _iconStyle,
133 size: 24,
134 type: 'navigation/more_vert_white'),
135 onGestureTap: _handleMenuClick
136 )
130 ] 137 ]
131 ); 138 );
132 139
133 var list = new Stocklist(stocks: _sortedStocks, query: _searchQuery); 140 var list = new Stocklist(stocks: _sortedStocks, query: _searchQuery);
134 141
135 var fab = new FloatingActionButton(content: new Icon( 142 var fab = new FloatingActionButton(content: new Icon(
136 type: 'content/add_white', size: 24), level: 3); 143 type: 'content/add_white', size: 24), level: 3);
137 144
138 var children = [ 145 var children = [
139 new Container( 146 new Container(
140 key: 'Content', 147 key: 'Content',
141 style: _style, 148 style: _style,
142 children: [toolbar, list] 149 children: [toolbar, list]
143 ), 150 ),
144 fab, 151 fab,
145 drawer 152 drawer
146 ]; 153 ];
147 154
148 if (_menuController.isOpen) { 155 if (_menuController != null) {
149 children.add(new StockMenu(controller: _menuController) 156 var menu = new EventTarget(
150 ..events.listen('gesturetap', (_) { 157 new StockMenu(controller: _menuController),
151 // TODO(abarth): We should close the menu when you tap away from the 158 onGestureTap: (_) {
152 // menu rather than when you tap on the menu. 159 // TODO(abarth): We should close the menu when you tap away from the
153 setState(() { 160 // menu rather than when you tap on the menu.
154 _menuController.close(); 161 setState(() {
155 }); 162 _menuController.close();
156 })); 163 _menuController = null;
164 });
165 }
166 );
167 children.add(menu);
157 } 168 }
158 169
159 return new Container(key: 'StocksApp', children: children); 170 return new Container(key: 'StocksApp', children: children);
160 } 171 }
161 } 172 }
OLDNEW
« no previous file with comments | « no previous file | sky/framework/components/button_base.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698