mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-12-19 05:19:42 +08:00
feat(nav-controller): goback best guess
This commit is contained in:
@@ -3,15 +3,26 @@ import { Injectable } from '@angular/core';
|
||||
@Injectable()
|
||||
export class NavController {
|
||||
|
||||
private goback = false;
|
||||
private direction = 0;
|
||||
private stack: string[] = [];
|
||||
|
||||
setGoback() {
|
||||
this.goback = true;
|
||||
this.direction = -1;
|
||||
}
|
||||
|
||||
consumeGoBack() {
|
||||
const goback = this.goback;
|
||||
this.goback = false;
|
||||
return goback;
|
||||
consumeDirection() {
|
||||
if (this.direction === 0) {
|
||||
const index = this.stack.indexOf(document.location.href);
|
||||
if (index === -1) {
|
||||
this.stack.push(document.location.href);
|
||||
this.direction = 1;
|
||||
} else {
|
||||
this.stack = this.stack.slice(0, index + 1);
|
||||
this.direction = -1;
|
||||
}
|
||||
}
|
||||
const direction = this.direction;
|
||||
this.direction = 0;
|
||||
return direction;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ export class IonRouterOutlet implements OnDestroy, OnInit {
|
||||
@Output('deactivate') deactivateEvents = new EventEmitter<any>();
|
||||
|
||||
constructor(
|
||||
private parentContexts: ChildrenOutletContexts, private location: ViewContainerRef,
|
||||
private parentContexts: ChildrenOutletContexts,
|
||||
private location: ViewContainerRef,
|
||||
private resolver: ComponentFactoryResolver,
|
||||
private elementRef: ElementRef,
|
||||
@Attribute('name') name: string,
|
||||
@@ -133,9 +134,12 @@ export class IonRouterOutlet implements OnDestroy, OnInit {
|
||||
const navEl = this.elementRef.nativeElement as HTMLIonRouterOutletElement;
|
||||
navEl.appendChild(enteringEl);
|
||||
|
||||
const direction = this.navCtrl.consumeDirection();
|
||||
|
||||
await navEl.componentOnReady();
|
||||
await navEl.commit(enteringEl, {
|
||||
direction: this.navCtrl.consumeGoBack() ? NavDirection.back : NavDirection.forward
|
||||
duration: direction === 0 ? 0 : undefined,
|
||||
direction: direction === -1 ? NavDirection.back : NavDirection.forward
|
||||
});
|
||||
|
||||
if (this.deactivated) {
|
||||
|
||||
Reference in New Issue
Block a user