Skip to content

Commit

Permalink
fix(nav): portal nav should always animate
Browse files Browse the repository at this point in the history
Closes #6059
  • Loading branch information
adamdbradley committed Apr 6, 2016
1 parent 49017c3 commit 86fc741
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 24 deletions.
34 changes: 20 additions & 14 deletions ionic/components/nav/nav-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ export class NavController extends Ion {
*/
config: Config;

/**
* @private
*/
isPortal: boolean = false;

constructor(
parent: any,
protected _app: IonicApp,
Expand Down Expand Up @@ -425,6 +430,10 @@ export class NavController extends Ion {
opts = {};
}

if (enteringView.usePortal && this._portal) {
return this._portal.present(enteringView, opts);
}

enteringView.setNav(rootNav);

opts.keyboardClose = false;
Expand All @@ -440,11 +449,6 @@ export class NavController extends Ion {
animation: enteringView.getTransitionName('back')
});

if (enteringView.usePortal && this._portal) {
this._portal.present(enteringView);
return;
}

// start the transition
return rootNav._insertViews(-1, [enteringView], opts);
}
Expand Down Expand Up @@ -740,7 +744,7 @@ export class NavController extends Ion {
// get the view thats ready to enter
let enteringView = this.getByState(STATE_INIT_ENTER);

if (!enteringView && this._portal) {
if (!enteringView && !this.isPortal) {
// oh nos! no entering view to go to!
// if there is no previous view that would enter in this nav stack
// and the option is set to climb up the nav parent looking
Expand Down Expand Up @@ -912,9 +916,7 @@ export class NavController extends Ion {
opts = {};
}

if (this.config.get('animate') === false || (this._views.length === 1 && !this._init)) {
opts.animate = false;
}
this._setAnimate(opts);

if (!leavingView) {
// if no leaving view then create a bogus one
Expand Down Expand Up @@ -943,6 +945,12 @@ export class NavController extends Ion {
});
}

private _setAnimate(opts: NavOptions) {
if ((this._views.length === 1 && !this._init && !this.isPortal) || this.config.get('animate') === false) {
opts.animate = false;
}
}

/**
* @private
*/
Expand Down Expand Up @@ -1097,9 +1105,7 @@ export class NavController extends Ion {
this._trans && this._trans.destroy();
this._trans = transAnimation;

// Portal elements should always animate
// so ignore this if it is a portal
if (opts.animate === false && this._portal) {
if (opts.animate === false) {
// force it to not animate the elements, just apply the "to" styles
transAnimation.duration(0);
}
Expand Down Expand Up @@ -1253,7 +1259,7 @@ export class NavController extends Ion {
this._app && this._app.setEnabled(true);
this.setTransitioning(false);

if (direction !== null && hasCompleted && this._portal) {
if (direction !== null && hasCompleted && !this.isPortal) {
// notify router of the state change if a direction was provided
// multiple routers can exist and each should be notified
this.routers.forEach(router => {
Expand Down Expand Up @@ -1662,7 +1668,7 @@ export class NavController extends Ion {

} else {
// this is the initial view
enteringView.setZIndex(this._portal ? INIT_ZINDEX : PORTAL_ZINDEX, this._renderer);
enteringView.setZIndex(this.isPortal ? PORTAL_ZINDEX : INIT_ZINDEX, this._renderer);
}

} else if (direction === 'back') {
Expand Down
1 change: 1 addition & 0 deletions ionic/components/nav/nav-portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export class Portal extends NavController {
renderer: Renderer
) {
super(hostNavCtrl, app, config, keyboard, elementRef, null, compiler, viewManager, zone, renderer);
this.isPortal = true;
}
}
65 changes: 55 additions & 10 deletions ionic/components/nav/test/nav-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,11 +641,11 @@ export function run() {
it('should set zIndex 9999 on first entering portal view', () => {
let enteringView = new ViewController();
enteringView.setPageRef({});
nav._portal = null;
nav.isPortal = true;
nav._setZIndex(enteringView, null, 'forward');
expect(enteringView.zIndex).toEqual(9999);
});

it('should set zIndex 10000 on second entering portal view', () => {
let leavingView = new ViewController();
leavingView.zIndex = 9999;
Expand All @@ -655,8 +655,8 @@ export function run() {
nav._portal = null;
nav._setZIndex(enteringView, leavingView, 'forward');
expect(enteringView.zIndex).toEqual(10000);
});
});

it('should set zIndex 9999 on entering portal view going back', () => {
let leavingView = new ViewController();
leavingView.zIndex = 10000;
Expand All @@ -666,7 +666,52 @@ export function run() {
nav._portal = null;
nav._setZIndex(enteringView, leavingView, 'back');
expect(enteringView.zIndex).toEqual(9999);
});
});

});

describe('_setAnimate', () => {

it('should be unchanged when the nav is a portal', () => {
nav._views = [new ViewController()];
nav._init = false;
nav.isPortal = true;
let opts: NavOptions = {};
nav._setAnimate(opts);
expect(opts.animate).toBeUndefined();
});

it('should not animate when theres only 1 view, and nav hasnt initialized yet', () => {
nav._views = [new ViewController()];
nav._init = false;
let opts: NavOptions = {};
nav._setAnimate(opts);
expect(opts.animate).toEqual(false);
});

it('should be unchanged when theres only 1 view, and nav has already initialized', () => {
nav._views = [new ViewController()];
nav._init = true;
let opts: NavOptions = {};
nav._setAnimate(opts);
expect(opts.animate).toBeUndefined();
});

it('should not animate with config animate = false, and has initialized', () => {
config.set('animate', false);
nav._init = true;
let opts: NavOptions = {};
nav._setAnimate(opts);
expect(opts.animate).toEqual(false);
});

it('should not animate with config animate = false, and has not initialized', () => {
config.set('animate', false);
nav._init = false;
let opts: NavOptions = {};
nav._setAnimate(opts);
expect(opts.animate).toEqual(false);
});

});

Expand Down Expand Up @@ -1134,25 +1179,25 @@ export function run() {
let enteringView = new ViewController();
enteringView.setPageRef({});
enteringView.usePortal = true;

expect(nav._portal.length()).toBe(0);
expect(nav.length()).toBe(0);
nav.present(enteringView);
expect(nav._portal.length()).toBe(1);
expect(nav.length()).toBe(0);
});

it('should present in main nav', () => {
let enteringView = new ViewController();
enteringView.setPageRef({});
enteringView.usePortal = false;

expect(nav._portal.length()).toBe(0);
expect(nav.length()).toBe(0);
nav.present(enteringView);
expect(nav._portal.length()).toBe(0);
expect(nav.length()).toBe(1);
});
});

});

Expand Down Expand Up @@ -1294,7 +1339,7 @@ export function run() {
setElementClass: function(){},
setElementStyle: function(){}
};

nav._portal = new NavController(null, null, config, null, elementRef, null, null, null, null, null);

return nav;
Expand Down

0 comments on commit 86fc741

Please sign in to comment.