feat(nav-controller): goback best guess

This commit is contained in:
Manu Mtz.-Almeida
2018-03-27 17:13:57 +02:00
parent 862e5719c6
commit 46bbd0fdf8
2 changed files with 23 additions and 8 deletions

View File

@@ -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;
}
}

View File

@@ -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) {