mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 20:33:32 +08:00
wip
This commit is contained in:
@ -230,10 +230,10 @@ export class NavController extends Ion {
|
||||
* @param {Object} [opts={}] Any options you want to use pass to transtion
|
||||
* @returns {Promise} Returns a promise when the transition is completed
|
||||
*/
|
||||
push(componentType, params = {}, opts = {}, callback) {
|
||||
push(componentType, params={}, opts={}, callback) {
|
||||
if (!componentType) {
|
||||
let errMsg = 'invalid componentType to push';
|
||||
console.error(errMsg)
|
||||
console.error(errMsg);
|
||||
return Promise.reject(errMsg);
|
||||
}
|
||||
|
||||
@ -245,13 +245,27 @@ export class NavController extends Ion {
|
||||
return Promise.reject('nav controller actively transitioning');
|
||||
}
|
||||
|
||||
this.setTransitioning(true, 500);
|
||||
|
||||
let promise = null;
|
||||
if (!callback) {
|
||||
promise = new Promise(res => { callback = res; });
|
||||
}
|
||||
|
||||
// create a new ViewController
|
||||
let enteringView = new ViewController(this, componentType, params);
|
||||
enteringView.pageType = opts.pageType;
|
||||
enteringView.handle = opts.handle || null;
|
||||
|
||||
this.pushView(enteringView, opts, callback);
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
pushView(enteringView, opts, callback) {
|
||||
this.setTransitioning(true, 500);
|
||||
|
||||
// do not animate if this is the first in the stack
|
||||
if (!this._views.length && !opts.animateFirst) {
|
||||
opts.animate = false;
|
||||
@ -260,6 +274,10 @@ export class NavController extends Ion {
|
||||
// default the direction to "forward"
|
||||
opts.direction = opts.direction || 'forward';
|
||||
|
||||
if (!opts.animation) {
|
||||
opts.animation = this.config.get(enteringView.enterAnimationKey);
|
||||
}
|
||||
|
||||
// the active view is going to be the leaving one (if one exists)
|
||||
let leavingView = this.getActive() || new ViewController();
|
||||
leavingView.shouldCache = (isBoolean(opts.cacheLeavingView) ? opts.cacheLeavingView : true);
|
||||
@ -268,25 +286,16 @@ export class NavController extends Ion {
|
||||
leavingView.willUnload();
|
||||
}
|
||||
|
||||
// create a new ViewController
|
||||
let enteringView = new ViewController(this, componentType, params);
|
||||
enteringView.shouldDestroy = false;
|
||||
enteringView.shouldCache = false;
|
||||
enteringView.pageType = opts.pageType;
|
||||
enteringView.handle = opts.handle || null;
|
||||
|
||||
// add the view to the stack
|
||||
this._add(enteringView);
|
||||
|
||||
if (this.router) {
|
||||
// notify router of the state change
|
||||
this.router.stateChange('push', enteringView, params);
|
||||
this.router.stateChange('push', enteringView, enteringView.params);
|
||||
}
|
||||
|
||||
// start the transition
|
||||
this._transition(enteringView, leavingView, opts, callback);
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -333,6 +342,10 @@ export class NavController extends Ion {
|
||||
leavingView.willUnload();
|
||||
}
|
||||
|
||||
if (!opts.animation) {
|
||||
opts.animation = this.config.get(leavingView.leaveAnimationKey);
|
||||
}
|
||||
|
||||
// the entering view is now the new last view
|
||||
// Note: we might not have an entering view if this is the
|
||||
// only view on the history stack.
|
||||
@ -655,9 +668,6 @@ export class NavController extends Ion {
|
||||
return done(enteringView);
|
||||
}
|
||||
|
||||
if (!opts.animation) {
|
||||
opts.animation = this.config.get('pageTransition');
|
||||
}
|
||||
if (this.config.get('animate') === false) {
|
||||
opts.animate = false;
|
||||
}
|
||||
@ -909,7 +919,7 @@ export class NavController extends Ion {
|
||||
|
||||
let providers = this.providers.concat(Injector.resolve([
|
||||
provide(ViewController, {useValue: viewCtrl}),
|
||||
provide(NavParams, {useValue: viewCtrl.params})
|
||||
provide(NavParams, {useValue: viewCtrl.getNavParams()})
|
||||
]));
|
||||
|
||||
let location = this.elementRef;
|
||||
|
@ -1,6 +1,5 @@
|
||||
import {NavParams} from './nav-controller';
|
||||
|
||||
|
||||
/**
|
||||
* @name ViewController
|
||||
* @description
|
||||
@ -18,14 +17,26 @@ import {NavParams} from './nav-controller';
|
||||
*/
|
||||
export class ViewController {
|
||||
|
||||
constructor(navCtrl, componentType, params = {}) {
|
||||
this.navCtrl = navCtrl;
|
||||
constructor(navCtrl, componentType, data={}) {
|
||||
this.setNav(navCtrl);
|
||||
this.componentType = componentType;
|
||||
this.params = new NavParams(params);
|
||||
this.data = data;
|
||||
this.instance = {};
|
||||
this.state = 0;
|
||||
this._destroys = [];
|
||||
this._loaded = false;
|
||||
this.shouldDestroy = false;
|
||||
this.shouldCache = false;
|
||||
this.enterAnimationKey = 'pageTransition';
|
||||
this.leaveAnimationKey = 'pageTransition';
|
||||
}
|
||||
|
||||
setNav(navCtrl) {
|
||||
this._nav = navCtrl;
|
||||
}
|
||||
|
||||
getNavParams() {
|
||||
return new NavParams(this.data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -35,8 +46,8 @@ export class ViewController {
|
||||
*/
|
||||
enableBack() {
|
||||
// update if it's possible to go back from this nav item
|
||||
if (this.navCtrl) {
|
||||
let previousItem = this.navCtrl.getPrevious(this);
|
||||
if (this._nav) {
|
||||
let previousItem = this._nav.getPrevious(this);
|
||||
// the previous view may exist, but if it's about to be destroyed
|
||||
// it shouldn't be able to go back to
|
||||
return !!(previousItem && !previousItem.shouldDestroy);
|
||||
@ -74,7 +85,7 @@ export class ViewController {
|
||||
* @returns {Number} Returns the index of this page within its NavController.
|
||||
*/
|
||||
get index() {
|
||||
return (this.navCtrl ? this.navCtrl.indexOf(this) : -1);
|
||||
return (this._nav ? this._nav.indexOf(this) : -1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user