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

Side by Side Diff: sky/sdk/lib/widgets/navigator.dart

Issue 1186273002: Simple support for routing in Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: fix imports 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
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 'basic.dart';
6
7 typedef UINode Builder(Navigator navigator);
abarth-chromium 2015/06/16 02:07:55 Please add a blank line below this line.
jackson 2015/06/16 16:46:37 Done.
8 abstract class RouteBase {
9 RouteBase({this.name});
10 final String name;
11 UINode build(Navigator navigator);
12 }
13
14 class Route extends RouteBase {
15 Route({String name, this.builder}) : super(name: name);
16 final Builder builder;
17 UINode build(Navigator navigator) => builder(navigator);
18 }
19
20 class Navigator extends Component {
21 Navigator({Object key, RouteBase initialRoute, this.routes})
22 : super(key: key, stateful: true) {
23 assert(initialRoute != null || routes != null && routes.length > 0);
24 currentRoute = initialRoute == null ? this.routes[0] : initialRoute;
abarth-chromium 2015/06/16 02:07:54 There's actually a subtle bug in this class. The
jackson 2015/06/16 16:46:37 Done.
25 }
26
27 RouteBase currentRoute;
28 List<RouteBase> routes;
29
30 void syncFields(Navigator source) {
31 currentRoute = source.currentRoute;
32 routes = source.routes;
33 }
34
35 void pushNamedRoute(String name) {
36 assert(routes != null);
37 for (RouteBase route in routes) {
38 if (route.name == name) {
39 setState(() {
40 currentRoute = route;
41 });
42 return;
43 }
44 }
45 assert(false); // route not found
46 }
47
48 void pushRoute(RouteBase route) {
49 setState(() {
50 currentRoute = route;
51 });
52 }
53
54 UINode build() {
55 return currentRoute.build(this);
abarth-chromium 2015/06/16 02:07:54 For example, if (currentRoute == null) return r
56 }
57 }
OLDNEW
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698