Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/components/ion-tabs/ion-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import {
Component, Optional, ElementRef, NgZone, Renderer, ComponentFactoryResolver, ChangeDetectorRef, ErrorHandler, OnInit,
OnDestroy, ViewEncapsulation
} from '@angular/core';
import { Tab, App, Config, Platform, GestureController, DeepLinker, DomController } from 'ionic-angular';
import { Tab, App, Config, Platform, GestureController, DeepLinker, DomController, NavOptions } from 'ionic-angular';
import { TransitionController } from 'ionic-angular/transitions/transition-controller';
import { CoreIonTabsComponent } from './ion-tabs';
import { TransitionDoneFn } from 'ionic-angular/navigation/nav-util';

/**
* Equivalent to ion-tab, but to be used inside core-ion-tabs.
Expand Down Expand Up @@ -58,4 +59,35 @@ export class CoreIonTabComponent extends Tab implements OnInit, OnDestroy {

this.parent.remove(this);
}

/**
* Push a page to the navigation stack. this similar to parent NavController, but perform some check to make
* sure one page won't open multiple time.
*/
push(page: any, params?: any, opts?: NavOptions, done?: TransitionDoneFn): Promise<any> {
if (this.isTransitioning()) {
// Try again later, the app is transitioning, this also happen when the page is first loaded.
return new Promise<any>((resolve, reject): void => {
setTimeout(() => {

return this.push(page, params, opts, done).then(resolve, reject);
}, 250);
});
} else {
const previousViews = this.getViews();
if (previousViews.length > 0) {
const previousView = previousViews[previousViews.length - 1];
const previousParam = previousView.getNavParams().data;

// If the view we pushing in have same page's name and identical params, then we won't do anything.
// This is Ionic issue when user clicking too fast on old device or slow internet connection.
if (previousView.name === page && JSON.stringify(previousParam) === JSON.stringify(params)) {

return Promise.resolve();
}
}

return super.push(page, params, opts, done);
}
}
}