| 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 '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/icon_button.dart'; | 10 import 'package:sky/framework/components/icon_button.dart'; |
| 11 import 'package:sky/framework/components/input.dart'; | 11 import 'package:sky/framework/components/input.dart'; |
| 12 import 'package:sky/framework/components/menu_divider.dart'; | 12 import 'package:sky/framework/components/menu_divider.dart'; |
| 13 import 'package:sky/framework/components/menu_item.dart'; | 13 import 'package:sky/framework/components/menu_item.dart'; |
| 14 import 'package:sky/framework/components/modal_overlay.dart'; |
| 14 import 'package:sky/framework/components/popup_menu.dart'; | 15 import 'package:sky/framework/components/popup_menu.dart'; |
| 15 import 'package:sky/framework/components/scaffold.dart'; | 16 import 'package:sky/framework/components/scaffold.dart'; |
| 16 import 'package:sky/framework/debug/tracing.dart'; | 17 import 'package:sky/framework/debug/tracing.dart'; |
| 17 import 'package:sky/framework/fn.dart'; | 18 import 'package:sky/framework/fn.dart'; |
| 18 import 'package:sky/framework/theme/typography.dart' as typography; | 19 import 'package:sky/framework/theme/typography.dart' as typography; |
| 19 import 'package:sky/framework/theme/colors.dart'; | 20 import 'package:sky/framework/theme/colors.dart'; |
| 20 import 'stock_data.dart'; | 21 import 'stock_data.dart'; |
| 21 import 'stock_list.dart'; | 22 import 'stock_list.dart'; |
| 22 import 'stock_menu.dart'; | 23 import 'stock_menu.dart'; |
| 23 | 24 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 54 }); | 55 }); |
| 55 } | 56 } |
| 56 | 57 |
| 57 void _handleSearchEnd(_) { | 58 void _handleSearchEnd(_) { |
| 58 setState(() { | 59 setState(() { |
| 59 _isSearching = false; | 60 _isSearching = false; |
| 60 _searchQuery = null; | 61 _searchQuery = null; |
| 61 }); | 62 }); |
| 62 } | 63 } |
| 63 | 64 |
| 64 void _handleSearchQueryChanged(query) { | 65 void _handleSearchQueryChanged(String query) { |
| 65 setState(() { | 66 setState(() { |
| 66 _searchQuery = query; | 67 _searchQuery = query; |
| 67 }); | 68 }); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void _handleMenuClick(_) { | 71 void _handleMenuShow(_) { |
| 71 setState(() { | 72 setState(() { |
| 72 _menuController = new PopupMenuController(); | 73 _menuController = new PopupMenuController(); |
| 73 _menuController.open(); | 74 _menuController.open(); |
| 74 }); | 75 }); |
| 75 } | 76 } |
| 76 | 77 |
| 78 void _handleMenuHide(_) { |
| 79 setState(() { |
| 80 _menuController.close().then((_) { |
| 81 setState(() { |
| 82 _menuController = null; |
| 83 }); |
| 84 }); |
| 85 }); |
| 86 } |
| 87 |
| 77 Drawer buildDrawer() { | 88 Drawer buildDrawer() { |
| 78 return new Drawer( | 89 return new Drawer( |
| 79 controller: _drawerController, | 90 controller: _drawerController, |
| 80 level: 3, | 91 level: 3, |
| 81 children: [ | 92 children: [ |
| 82 new DrawerHeader(children: [new Text('Stocks')]), | 93 new DrawerHeader(children: [new Text('Stocks')]), |
| 83 new MenuItem( | 94 new MenuItem( |
| 84 key: 'Inbox', | 95 key: 'Inbox', |
| 85 icon: 'content/inbox', | 96 icon: 'content/inbox', |
| 86 children: [new Text('Inbox')]), | 97 children: [new Text('Inbox')]), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 109 onGestureTap: _drawerController.toggle), | 120 onGestureTap: _drawerController.toggle), |
| 110 center: new Container( | 121 center: new Container( |
| 111 style: _titleStyle, | 122 style: _titleStyle, |
| 112 children: [new Text('Stocks')]), | 123 children: [new Text('Stocks')]), |
| 113 right: [ | 124 right: [ |
| 114 new IconButton( | 125 new IconButton( |
| 115 icon: 'action/search_white', | 126 icon: 'action/search_white', |
| 116 onGestureTap: _handleSearchBegin), | 127 onGestureTap: _handleSearchBegin), |
| 117 new IconButton( | 128 new IconButton( |
| 118 icon: 'navigation/more_vert_white', | 129 icon: 'navigation/more_vert_white', |
| 119 onGestureTap: _handleMenuClick) | 130 onGestureTap: _handleMenuShow) |
| 120 ]), | 131 ]), |
| 121 _actionBarStyle); | 132 _actionBarStyle); |
| 122 } | 133 } |
| 123 | 134 |
| 124 // TODO(abarth): Should we factor this into a SearchBar in the framework? | 135 // TODO(abarth): Should we factor this into a SearchBar in the framework? |
| 125 Node buildSearchBar() { | 136 Node buildSearchBar() { |
| 126 return new StyleNode( | 137 return new StyleNode( |
| 127 new ActionBar( | 138 new ActionBar( |
| 128 left: new IconButton( | 139 left: new IconButton( |
| 129 icon: 'navigation/arrow_back_grey600', | 140 icon: 'navigation/arrow_back_grey600', |
| 130 onGestureTap: _handleSearchEnd), | 141 onGestureTap: _handleSearchEnd), |
| 131 center: new Input( | 142 center: new Input( |
| 132 focused: true, | 143 focused: true, |
| 133 placeholder: 'Search stocks', | 144 placeholder: 'Search stocks', |
| 134 onChanged: _handleSearchQueryChanged)), | 145 onChanged: _handleSearchQueryChanged)), |
| 135 _searchBarStyle); | 146 _searchBarStyle); |
| 136 } | 147 } |
| 137 | 148 |
| 149 void addMenuToOverlays(List<Node> overlays) { |
| 150 if (_menuController == null) |
| 151 return; |
| 152 overlays.add(new ModalOverlay( |
| 153 children: [new StockMenu(controller: _menuController)], |
| 154 onDismiss: _handleMenuHide)); |
| 155 } |
| 156 |
| 138 Node build() { | 157 Node build() { |
| 139 List<Node> overlays = []; | 158 List<Node> overlays = []; |
| 140 | 159 addMenuToOverlays(overlays); |
| 141 if (_menuController != null) { | |
| 142 overlays.add(new EventTarget( | |
| 143 new StockMenu(controller: _menuController), | |
| 144 onGestureTap: (_) { | |
| 145 // TODO(abarth): We should close the menu when you tap away from the | |
| 146 // menu rather than when you tap on the menu. | |
| 147 setState(() { | |
| 148 _menuController.close().then((_) { | |
| 149 setState(() { | |
| 150 _menuController = null; | |
| 151 }); | |
| 152 }); | |
| 153 }); | |
| 154 } | |
| 155 )); | |
| 156 } | |
| 157 | 160 |
| 158 return new Scaffold( | 161 return new Scaffold( |
| 159 header: _isSearching ? buildSearchBar() : buildActionBar(), | 162 header: _isSearching ? buildSearchBar() : buildActionBar(), |
| 160 content: new Stocklist(stocks: _stocks, query: _searchQuery), | 163 content: new Stocklist(stocks: _stocks, query: _searchQuery), |
| 161 fab: new FloatingActionButton( | 164 fab: new FloatingActionButton( |
| 162 content: new Icon(type: 'content/add_white', size: 24), level: 3), | 165 content: new Icon(type: 'content/add_white', size: 24), level: 3), |
| 163 drawer: buildDrawer(), | 166 drawer: buildDrawer(), |
| 164 overlays: overlays | 167 overlays: overlays |
| 165 ); | 168 ); |
| 166 } | 169 } |
| 167 } | 170 } |
| OLD | NEW |