mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
feat(navController): navController insert method
This commit is contained in:
@ -159,6 +159,27 @@ export class NavController extends Ion {
|
|||||||
* @param {TODO} [opts={}] TODO
|
* @param {TODO} [opts={}] TODO
|
||||||
* @returns {Promise} TODO
|
* @returns {Promise} TODO
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
insert(componentType, index) {
|
||||||
|
if (!componentType || index < 0) {
|
||||||
|
return Promise.reject();
|
||||||
|
}
|
||||||
|
|
||||||
|
// push it onto the end
|
||||||
|
if (index >= this.views.length) {
|
||||||
|
return this.push(componentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
// create new ViewController, but don't render yet
|
||||||
|
let viewCtrl = new ViewController(this, componentType);
|
||||||
|
viewCtrl.state = CACHED_STATE;
|
||||||
|
viewCtrl.shouldDestroy = false;
|
||||||
|
viewCtrl.shouldCache = false;
|
||||||
|
|
||||||
|
this._incrementId(viewCtrl);
|
||||||
|
this.views.splice(index, 0, viewCtrl);
|
||||||
|
}
|
||||||
|
|
||||||
setViews(components, opts = {}) {
|
setViews(components, opts = {}) {
|
||||||
if (!components || !components.length) {
|
if (!components || !components.length) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
@ -668,10 +689,14 @@ export class NavController extends Ion {
|
|||||||
* @returns {TODO} TODO
|
* @returns {TODO} TODO
|
||||||
*/
|
*/
|
||||||
add(view) {
|
add(view) {
|
||||||
view.id = this.id + '-' + (++this._ids);
|
this._incrementId(view);
|
||||||
this.views.push(view);
|
this.views.push(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_incrementId(view) {
|
||||||
|
view.id = this.id + '-' + (++this._ids);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* TODO
|
||||||
* @param {TODO} viewOrIndex TODO
|
* @param {TODO} viewOrIndex TODO
|
||||||
|
@ -100,6 +100,7 @@ class SecondPage {
|
|||||||
<ion-content padding>
|
<ion-content padding>
|
||||||
<p>
|
<p>
|
||||||
<button id="from3To2" (click)="pop()">Pop (Go back to 2nd)</button>
|
<button id="from3To2" (click)="pop()">Pop (Go back to 2nd)</button>
|
||||||
|
<button id="insert" (click)="insert()">Insert first page into history before this</button>
|
||||||
</p>
|
</p>
|
||||||
<div class="yellow"><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f></div>
|
<div class="yellow"><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f><f></f></div>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
@ -116,6 +117,10 @@ class ThirdPage {
|
|||||||
this.nav.pop()
|
this.nav.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
insert() {
|
||||||
|
this.nav.insert(FirstPage, 2);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user