Exemplo n.º 1
0
        public IPromise <object> push(Route route)
        {
            D.assert(!this._debugLocked);
            D.assert(() => {
                this._debugLocked = true;
                return(true);
            });
            D.assert(route != null);
            D.assert(route._navigator == null);
            var oldRoute = this._history.isNotEmpty() ? this._history.last() : null;

            route._navigator = this;
            route.install(this._currentOverlayEntry);
            this._history.Add(route);
            route.didPush();
            route.didChangeNext(null);
            if (oldRoute != null)
            {
                oldRoute.didChangeNext(route);
                route.didChangePrevious(oldRoute);
            }

            foreach (var observer in this.widget.observers)
            {
                observer.didPush(route, oldRoute);
            }

            D.assert(() => {
                this._debugLocked = false;
                return(true);
            });
            this._afterNavigation();
            return(route.popped);
        }
Exemplo n.º 2
0
        public IPromise <object> pushAndRemoveUntil(Route newRoute, RoutePredicate predicate)
        {
            D.assert(!this._debugLocked);
            D.assert(() => {
                this._debugLocked = true;
                return(true);
            });
            var removedRoutes = new List <Route>();

            while (this._history.isNotEmpty() && !predicate(this._history.last()))
            {
                var removedRoute = this._history.last();
                this._history.RemoveAt(this._history.Count - 1);
                D.assert(removedRoute != null && removedRoute._navigator == this);
                D.assert(removedRoute.overlayEntries.isNotEmpty());
                removedRoutes.Add(removedRoute);
            }

            D.assert(newRoute._navigator == null);
            D.assert(newRoute.overlayEntries.isEmpty());
            var oldRoute = this._history.isNotEmpty() ? this._history.last() : null;

            newRoute._navigator = this;
            newRoute.install(this._currentOverlayEntry);
            this._history.Add(newRoute);
            newRoute.didPush().whenCompleteOrCancel(() => {
                if (this.mounted)
                {
                    foreach (var route in removedRoutes)
                    {
                        route.dispose();
                    }
                }
            });
            newRoute.didChangeNext(null);
            if (oldRoute != null)
            {
                oldRoute.didChangeNext(newRoute);
            }

            foreach (var observer in this.widget.observers)
            {
                observer.didPush(newRoute, oldRoute);
                foreach (var removedRoute in removedRoutes)
                {
                    observer.didRemove(removedRoute, oldRoute);
                }
            }

            D.assert(() => {
                this._debugLocked = false;
                return(true);
            });
            this._afterNavigation();
            return(newRoute.popped);
        }
Exemplo n.º 3
0
        public IPromise <object> pushReplacement(Route newRoute, object result = null)
        {
            D.assert(!this._debugLocked);
            D.assert(() => {
                this._debugLocked = true;
                return(true);
            });
            var oldRoute = this._history.last();

            D.assert(oldRoute != null && oldRoute._navigator == this);
            D.assert(oldRoute.overlayEntries.isNotEmpty());
            D.assert(newRoute._navigator == null);
            D.assert(newRoute.overlayEntries.isEmpty());
            var index = this._history.Count - 1;

            D.assert(index >= 0);
            D.assert(this._history.IndexOf(oldRoute) == index);
            newRoute._navigator = this;
            newRoute.install(this._currentOverlayEntry);
            this._history[index] = newRoute;
            newRoute.didPush().whenCompleteOrCancel(() => {
                if (this.mounted)
                {
                    oldRoute.didComplete(result ?? oldRoute.currentResult);
                    oldRoute.dispose();
                }
            });
            newRoute.didChangeNext(null);
            if (index > 0)
            {
                this._history[index - 1].didChangeNext(newRoute);
                newRoute.didChangePrevious(this._history[index - 1]);
            }

            foreach (var observer in this.widget.observers)
            {
                observer.didReplace(newRoute: newRoute, oldRoute: oldRoute);
            }

            D.assert(() => {
                this._debugLocked = false;
                return(true);
            });
            this._afterNavigation();
            return(newRoute.popped);
        }