Chromium Code Reviews| Index: sky/sdk/lib/widgets/navigator.dart |
| diff --git a/sky/sdk/lib/widgets/navigator.dart b/sky/sdk/lib/widgets/navigator.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dc4c0bc9ab28fd4d5007f81e7c3bae2cfeeafd76 |
| --- /dev/null |
| +++ b/sky/sdk/lib/widgets/navigator.dart |
| @@ -0,0 +1,57 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +import 'basic.dart'; |
| + |
| +typedef UINode Builder(Navigator navigator); |
| + |
| +abstract class RouteBase { |
| + RouteBase({this.name}); |
|
Hixie
2015/06/16 16:55:09
Spaces around the parameters.
jackson
2015/06/16 18:27:27
Done.
|
| + final String name; |
| + UINode build(Navigator navigator); |
| +} |
| + |
| +class Route extends RouteBase { |
| + Route({String name, this.builder}) : super(name: name); |
|
Hixie
2015/06/16 16:55:09
Spaces here too.
jackson
2015/06/16 18:27:27
Done.
|
| + final Builder builder; |
| + UINode build(Navigator navigator) => builder(navigator); |
| +} |
| + |
| +class Navigator extends Component { |
| + Navigator({Object key, this.currentRoute, this.routes}) |
|
Hixie
2015/06/16 16:55:09
Here too.
jackson
2015/06/16 18:27:27
Done.
|
| + : super(key: key, stateful: true); |
| + |
| + RouteBase currentRoute; |
| + List<RouteBase> routes; |
|
Hixie
2015/06/16 16:55:09
Maybe add a comment that "routes" is just the _nam
jackson
2015/06/16 18:27:27
I'll rename it to namedRoutes for now and make it
|
| + |
| + void syncFields(Navigator source) { |
| + currentRoute = source.currentRoute; |
| + routes = source.routes; |
| + } |
| + |
| + void pushNamedRoute(String name) { |
|
Hixie
2015/06/16 16:55:09
Why "push"?
jackson
2015/06/16 18:27:27
Because I'm implementing pop shortly. :)
|
| + assert(routes != null); |
| + for (RouteBase route in routes) { |
|
Hixie
2015/06/16 16:55:09
You can do this way more efficiently if you use a
jackson
2015/06/16 18:27:27
Agree, but see above
|
| + if (route.name == name) { |
| + setState(() { |
| + currentRoute = route; |
| + }); |
| + return; |
| + } |
| + } |
| + assert(false); // route not found |
| + } |
| + |
| + void pushRoute(RouteBase route) { |
| + setState(() { |
| + currentRoute = route; |
| + }); |
| + } |
| + |
| + UINode build() { |
| + Route route = currentRoute == null ? routes[0] : currentRoute; |
|
Hixie
2015/06/16 16:55:09
If you switch to using a map, then maybe have an i
jackson
2015/06/16 18:27:27
OK
|
| + assert(route != null); |
| + return route.build(this); |
| + } |
| +} |