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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..8f0d62be423690ebedcdc12781a7aee80de860be
--- /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);
abarth-chromium 2015/06/16 02:07:55 Please add a blank line below this line.
jackson 2015/06/16 16:46:37 Done.
+abstract class RouteBase {
+ RouteBase({this.name});
+ final String name;
+ UINode build(Navigator navigator);
+}
+
+class Route extends RouteBase {
+ Route({String name, this.builder}) : super(name: name);
+ final Builder builder;
+ UINode build(Navigator navigator) => builder(navigator);
+}
+
+class Navigator extends Component {
+ Navigator({Object key, RouteBase initialRoute, this.routes})
+ : super(key: key, stateful: true) {
+ assert(initialRoute != null || routes != null && routes.length > 0);
+ 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.
+ }
+
+ RouteBase currentRoute;
+ List<RouteBase> routes;
+
+ void syncFields(Navigator source) {
+ currentRoute = source.currentRoute;
+ routes = source.routes;
+ }
+
+ void pushNamedRoute(String name) {
+ assert(routes != null);
+ for (RouteBase route in routes) {
+ if (route.name == name) {
+ setState(() {
+ currentRoute = route;
+ });
+ return;
+ }
+ }
+ assert(false); // route not found
+ }
+
+ void pushRoute(RouteBase route) {
+ setState(() {
+ currentRoute = route;
+ });
+ }
+
+ UINode build() {
+ return currentRoute.build(this);
abarth-chromium 2015/06/16 02:07:54 For example, if (currentRoute == null) return r
+ }
+}
« 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