From ecb5e4f03123f93acd650bcde95f2be69ac1b430 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Fri, 29 Jan 2016 23:31:51 -0600 Subject: [PATCH] test(alert): dismiss alert, then run nav.pop() --- ionic/components/modal/test/basic/index.ts | 21 +++++++++++++-- ionic/components/nav/nav-controller.ts | 15 ++++++----- ionic/components/nav/nav.ts | 2 +- ionic/components/nav/test/basic/index.ts | 30 ++++++++++++++++++++-- 4 files changed, 57 insertions(+), 11 deletions(-) diff --git a/ionic/components/modal/test/basic/index.ts b/ionic/components/modal/test/basic/index.ts index 394ccc4fdc..c4144aa706 100644 --- a/ionic/components/modal/test/basic/index.ts +++ b/ionic/components/modal/test/basic/index.ts @@ -206,7 +206,7 @@ class ModalFirstPage { buttons: [ { text: 'Destructive', - style: 'destructive', + role: 'destructive', handler: () => { console.log('Destructive clicked'); } @@ -217,9 +217,26 @@ class ModalFirstPage { console.log('Archive clicked'); } }, + { + text: 'Go To Root', + handler: () => { + // overlays are added and removed from the root navigation + // find the root navigation, and pop this alert + // when the alert is done animating out, then pop off the modal + this.nav.rootNav.pop().then(() => { + this.nav.rootNav.pop(); + }); + + // by default an alert will dismiss itself + // however, we don't want to use the default + // but rather fire off our own pop navigation + // return false so it doesn't pop automatically + return false; + } + }, { text: 'Cancel', - style: 'cancel', + role: 'cancel', handler: () => { console.log('cancel this clicked'); } diff --git a/ionic/components/nav/nav-controller.ts b/ionic/components/nav/nav-controller.ts index 956c56c5f4..6fe2a5d527 100644 --- a/ionic/components/nav/nav-controller.ts +++ b/ionic/components/nav/nav-controller.ts @@ -643,13 +643,16 @@ export class NavController extends Ion { * } * ``` * - * @param {number} startIndex The starting index to remove views from the nav stack - * @param {removeCount} [opts={}] The number of views to remove, defaults to remove `1`. - * @param {object} [opts={}] Any options you want to use pass to transtion - * @returns {Promise} Returns a promise when the view has been removed + * @param {number} [startIndex] The starting index to remove pages from the stack. Default is the index of the last page. + * @param {number} [removeCount] The number of pages to remove, defaults to remove `1`. + * @param {object} [opts={}] Any options you want to use pass to transtion. + * @returns {Promise} Returns a promise when the page has been removed. */ - remove(startIndex: number, removeCount: number = 1, opts: any = {}): Promise { - if (startIndex < 0 || startIndex >= this._views.length) { + remove(startIndex: number = -1, removeCount: number = 1, opts: any = {}): Promise { + if (startIndex === -1) { + startIndex = this._views.length - 1; + + } else if (startIndex < 0 || startIndex >= this._views.length) { return Promise.reject("remove index out of range"); } diff --git a/ionic/components/nav/nav.ts b/ionic/components/nav/nav.ts index 23e59fecae..a05d0d9a7f 100644 --- a/ionic/components/nav/nav.ts +++ b/ionic/components/nav/nav.ts @@ -1,4 +1,4 @@ -import {Component, Directive, ElementRef, Host, Input, Optional, forwardRef, Inject, NgZone, Compiler, AppViewManager, Renderer, ViewContainerRef, Type} from 'angular2/core'; +import {Component, ElementRef, Input, Optional, NgZone, Compiler, AppViewManager, Renderer, Type, ViewChild} from 'angular2/core'; import {IonicApp} from '../app/app'; import {Config} from '../../config/config'; diff --git a/ionic/components/nav/test/basic/index.ts b/ionic/components/nav/test/basic/index.ts index a35b075d84..c45476d72a 100644 --- a/ionic/components/nav/test/basic/index.ts +++ b/ionic/components/nav/test/basic/index.ts @@ -1,7 +1,7 @@ import {Component, Type} from 'angular2/core'; -import {App, NavController} from 'ionic/ionic'; +import {App, NavController, Alert} from 'ionic/ionic'; import {Page, Config, IonicApp} from 'ionic/ionic'; -import {NavParams, NavController, ViewController, IONIC_DIRECTIVES} from 'ionic/ionic'; +import {NavParams, ViewController, IONIC_DIRECTIVES} from 'ionic/ionic'; @Component({ @@ -127,6 +127,7 @@ class FirstPage {

+

` }) @@ -157,6 +158,31 @@ class FullPage { this.nav.push(FirstPage); } + presentAlert() { + let alert = Alert.create(); + alert.setTitle('Hello Alert'); + alert.setMessage('Dismiss this alert, then pop one page'); + alert.addButton({ + text: 'Dismiss', + role: 'cancel', + handler: () => { + // overlays are added and removed from the root navigation + // ensure you using the root navigation, and pop this alert + // when the alert is done animating out, then pop off the active page + this.nav.rootNav.pop().then(() => { + this.nav.rootNav.pop(); + }); + + // by default an alert will dismiss itself + // however, we don't want to use the default + // but rather fire off our own pop navigation + // return false so it doesn't pop automatically + return false; + } + }); + this.nav.present(alert); + } + }