From 1dd73aac7a76ca350ecb930660641ddfeae7f0cd Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Sat, 12 Mar 2016 05:05:29 -0600 Subject: [PATCH] fix(nav): correctly set zIndex when there's a previous view --- ionic/components/alert/test/dismiss/index.ts | 38 ++++++++++++++++--- ionic/components/nav/nav-controller.ts | 14 ++++++- .../nav/test/nav-controller.spec.ts | 28 +++++++++++++- 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/ionic/components/alert/test/dismiss/index.ts b/ionic/components/alert/test/dismiss/index.ts index 85e10abee4..7c941749de 100644 --- a/ionic/components/alert/test/dismiss/index.ts +++ b/ionic/components/alert/test/dismiss/index.ts @@ -13,10 +13,6 @@ export class E2EPage { title: 'Not logged in', message: 'Sign in to continue.', buttons: [ - { - text: 'Cancel', - role: 'cancel' - }, { text: 'Sign in', handler: () => { @@ -45,7 +41,39 @@ export class E2EPage { ` }) -class AnotherPage {} +class AnotherPage { + + constructor(private nav: NavController) {} + + onPageDidEnter() { + this.showConfirm(); + } + + showConfirm() { + const alert = Alert.create({ + title: `Hi there`, + buttons: [ + { + text: 'Go Back', + role: 'cancel', + handler: () => { + alert.dismiss().then(() => { + this.nav.pop(); + }) + } + }, + { + text: 'Stay Here', + handler: () => { + console.log('Stay Here'); + } + } + ] + }); + this.nav.present(alert); + } + +} @App({ diff --git a/ionic/components/nav/nav-controller.ts b/ionic/components/nav/nav-controller.ts index 8abfdd766d..a9c1a41e6f 100644 --- a/ionic/components/nav/nav-controller.ts +++ b/ionic/components/nav/nav-controller.ts @@ -1641,7 +1641,19 @@ export class NavController extends Ion { if (enteringView) { // get the leaving view, which could be in various states if (!leavingView || !leavingView.isLoaded()) { - enteringView.setZIndex(INIT_ZINDEX, this._renderer); + // the leavingView is a mocked view, either we're + // actively transitioning or it's the initial load + + var previousView = this.getPrevious(enteringView); + if (previousView && previousView.isLoaded()) { + // we found a better previous view to reference + // use this one instead + enteringView.setZIndex(previousView.zIndex + 1, this._renderer); + + } else { + // this is the initial view + enteringView.setZIndex(INIT_ZINDEX, this._renderer); + } } else if (direction === 'back') { // moving back diff --git a/ionic/components/nav/test/nav-controller.spec.ts b/ionic/components/nav/test/nav-controller.spec.ts index 7253dbab2a..7a960b1288 100644 --- a/ionic/components/nav/test/nav-controller.spec.ts +++ b/ionic/components/nav/test/nav-controller.spec.ts @@ -585,7 +585,33 @@ export function run() { }); describe('_setZIndex', () => { - it('should set zIndex 10 on first entering view', () => { + + it('should set zIndex off of the previous view to the entering view is loaded and the leavingView is not loaded', () => { + let leavingView = new ViewController(); + leavingView.zIndex = 100; + leavingView._loaded = true; + let enteringView = new ViewController(); + enteringView.setPageRef({}); + + nav._views = [leavingView, enteringView]; + + nav._setZIndex(enteringView, leavingView, 'forward'); + expect(enteringView.zIndex).toEqual(101); + }); + + it('should set zIndex 100 when leaving view is not loaded', () => { + let leavingView = new ViewController(); + leavingView._loaded = false; + let enteringView = new ViewController(); + enteringView.setPageRef({}); + + nav._views = [leavingView, enteringView]; + + nav._setZIndex(enteringView, leavingView, 'forward'); + expect(enteringView.zIndex).toEqual(100); + }); + + it('should set zIndex 100 on first entering view', () => { let enteringView = new ViewController(); enteringView.setPageRef({}); nav._setZIndex(enteringView, null, 'forward');