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

Unified Diff: sky/sdk/lib/widgets/navigator.dart

Issue 1191153002: Make back button control drawer in stocks app (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: abarth feedback 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/lib/widgets/drawer.dart ('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
index 3a6cad179874b1d5078649fecd86c794fb0bfb5d..8ec482303966bc77530f1930028a177e9adeb2f2 100644
--- a/sky/sdk/lib/widgets/navigator.dart
+++ b/sky/sdk/lib/widgets/navigator.dart
@@ -4,18 +4,34 @@
import 'basic.dart';
-typedef Widget Builder(Navigator navigator);
+typedef Widget Builder(Navigator navigator, RouteBase route);
abstract class RouteBase {
RouteBase({ this.name });
final String name;
- Widget build(Navigator navigator);
+ Widget build(Navigator navigator, RouteBase route);
+ void popState() { }
}
class Route extends RouteBase {
Route({ String name, this.builder }) : super(name: name);
final Builder builder;
- Widget build(Navigator navigator) => builder(navigator);
+ Widget build(Navigator navigator, RouteBase route) => builder(navigator, route);
+}
+
+class RouteState extends RouteBase {
+
+ RouteState({this.callback, this.route, String name}) : super(name: name);
+
+ RouteBase route;
+ Function callback;
+
+ Widget build(Navigator navigator, _) => route.build(navigator, this);
+
+ void popState() {
+ if (callback != null)
+ callback(this);
+ }
}
class NavigationState {
@@ -51,25 +67,16 @@ class NavigationState {
void pop() {
if (historyIndex > 0) {
+ history[historyIndex].popState();
history.removeLast();
historyIndex--;
}
}
-
- void back() {
- if (historyIndex > 0)
- historyIndex--;
- }
-
- void forward() {
- historyIndex++;
- assert(historyIndex < history.length);
- }
}
class Navigator extends Component {
- Navigator(this.state, { String key }) : super(key: key);
+ Navigator(this.state, { String key }) : super(key: key, stateful: true);
NavigationState state;
@@ -77,6 +84,17 @@ class Navigator extends Component {
state = source.state;
}
+ RouteBase get currentRoute => state.currentRoute;
+
+ void pushState(String name, Function callback) {
+ RouteBase route = new RouteState(
+ name: name,
+ callback: callback,
+ route: state.currentRoute
+ );
+ push(route);
+ }
+
void pushNamed(String name) {
setState(() {
state.pushNamed(name);
@@ -95,19 +113,7 @@ class Navigator extends Component {
});
}
- void back() {
- setState(() {
- state.back();
- });
- }
-
- void forward() {
- setState(() {
- state.forward();
- });
- }
-
Widget build() {
- return state.currentRoute.build(this);
+ return state.currentRoute.build(this, state.currentRoute);
}
}
« no previous file with comments | « sky/sdk/lib/widgets/drawer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698