Skip to content

Commit

Permalink
feat(nav-controller): goback best guess
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Mar 27, 2018
1 parent 862e571 commit 46bbd0f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
23 changes: 17 additions & 6 deletions angular/src/navigation/ion-nav-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 6 additions & 2 deletions angular/src/navigation/ion-router-outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 46bbd0f

Please sign in to comment.