From c51260ac9640e035b96a4f6a4222d404ff8c4475 Mon Sep 17 00:00:00 2001 From: Hixie Date: Fri, 20 Nov 2015 16:19:34 -0800 Subject: [PATCH] Clean up the term "modal" in the navigator Now we only use it for things related to ModalRoute and ModalBarrier. (This is easy now that ephemeral routes are gone, so there's no other kind of route to distinguish against.) --- .../lib/src/widgets/hero_controller.dart | 4 +- .../flutter/lib/src/widgets/navigator.dart | 43 +++++++++---------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/packages/flutter/lib/src/widgets/hero_controller.dart b/packages/flutter/lib/src/widgets/hero_controller.dart index fb2eb082fd7..fc1b79562c6 100644 --- a/packages/flutter/lib/src/widgets/hero_controller.dart +++ b/packages/flutter/lib/src/widgets/hero_controller.dart @@ -24,7 +24,7 @@ class HeroController extends NavigatorObserver { final List _overlayEntries = new List(); - void didPushModal(Route route, Route previousRoute) { + void didPush(Route route, Route previousRoute) { assert(navigator != null); assert(route != null); if (route is ModalRoute) { // as opposed to StateRoute, say @@ -37,7 +37,7 @@ class HeroController extends NavigatorObserver { } } - void didPopModal(Route route, Route previousRoute) { + void didPop(Route route, Route previousRoute) { assert(navigator != null); assert(route != null); if (route is ModalRoute) { // as opposed to StateRoute, say diff --git a/packages/flutter/lib/src/widgets/navigator.dart b/packages/flutter/lib/src/widgets/navigator.dart index 7eee37316f2..8452e854e3a 100644 --- a/packages/flutter/lib/src/widgets/navigator.dart +++ b/packages/flutter/lib/src/widgets/navigator.dart @@ -13,13 +13,13 @@ abstract class Route { /// The given route has been pushed onto the navigator after this route. /// Return true if the route before this one should be notified also. The /// first route to return false will be the one passed to the - /// NavigatorObserver's didPushModal() as the previousRoute. + /// NavigatorObserver's didPush() as the previousRoute. bool willPushNext(Route nextRoute) => false; /// The given route, which came after this one, has been popped off the /// navigator. Return true if the route before this one should be notified /// also. The first route to return false will be the one passed to the - /// NavigatorObserver's didPushModal() as the previousRoute. + /// NavigatorObserver's didPush() as the previousRoute. bool didPopNext(Route nextRoute) => false; } @@ -34,8 +34,8 @@ typedef Route RouteFactory(NamedRouteSettings settings); class NavigatorObserver { NavigatorState _navigator; NavigatorState get navigator => _navigator; - void didPushModal(Route route, Route previousRoute) { } - void didPopModal(Route route, Route previousRoute) { } + void didPush(Route route, Route previousRoute) { } + void didPop(Route route, Route previousRoute) { } } class Navigator extends StatefulComponent { @@ -61,8 +61,7 @@ class Navigator extends StatefulComponent { class NavigatorState extends State { final GlobalKey _overlayKey = new GlobalKey(); - // TODO(ianh): Rename _modal to _history or some such - final List _modal = new List(); + final List _history = new List(); void initState() { super.initState(); @@ -84,11 +83,11 @@ class NavigatorState extends State { super.dispose(); } - bool get hasPreviousRoute => _modal.length > 1; + bool get hasPreviousRoute => _history.length > 1; OverlayState get overlay => _overlayKey.currentState; OverlayEntry get _currentOverlay { - for (Route route in _modal.reversed) { + for (Route route in _history.reversed) { if (route.overlayEntries.isNotEmpty) return route.overlayEntries.last; } @@ -106,12 +105,12 @@ class NavigatorState extends State { void push(Route route, { Set mostValuableKeys }) { setState(() { - int index = _modal.length-1; - while (index >= 0 && _modal[index].willPushNext(route)) + int index = _history.length-1; + while (index >= 0 && _history[index].willPushNext(route)) index -= 1; route.didPush(overlay, _currentOverlay); - config.observer?.didPushModal(route, index >= 0 ? _modal[index] : null); - _modal.add(route); + config.observer?.didPush(route, index >= 0 ? _history[index] : null); + _history.add(route); }); } @@ -126,13 +125,13 @@ class NavigatorState extends State { /// The type of the result argument, if provided, must match the type argument /// of the class of the given route. (In practice, this is usually "dynamic".) void remove(Route route, [dynamic result]) { - assert(_modal.contains(route)); + assert(_history.contains(route)); assert(route.overlayEntries.isEmpty); - if (_modal.last == route) { + if (_history.last == route) { pop(result); } else { setState(() { - _modal.remove(route); + _history.remove(route); route.didPop(result); }); } @@ -149,21 +148,21 @@ class NavigatorState extends State { // We use setState to guarantee that we'll rebuild, since the routes can't // do that for themselves, even if they have changed their own state (e.g. // ModalScope.isCurrent). - assert(_modal.length > 1); - Route route = _modal.removeLast(); + assert(_history.length > 1); + Route route = _history.removeLast(); route.didPop(result); - int index = _modal.length-1; - while (index >= 0 && _modal[index].didPopNext(route)) + int index = _history.length-1; + while (index >= 0 && _history[index].didPopNext(route)) index -= 1; - config.observer?.didPopModal(route, index >= 0 ? _modal[index] : null); + config.observer?.didPop(route, index >= 0 ? _history[index] : null); }); } Widget build(BuildContext context) { - assert(_modal.isNotEmpty); + assert(_history.isNotEmpty); return new Overlay( key: _overlayKey, - initialEntries: _modal.first.overlayEntries + initialEntries: _history.first.overlayEntries ); } }