diff --git a/src/components/ion-tabs/ion-tab.ts b/src/components/ion-tabs/ion-tab.ts index 0d656594f..313f55db7 100644 --- a/src/components/ion-tabs/ion-tab.ts +++ b/src/components/ion-tabs/ion-tab.ts @@ -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. @@ -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 { + if (this.isTransitioning()) { + // Try again later, the app is transitioning, this also happen when the page is first loaded. + return new Promise((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); + } + } }