Skip to content

Commit 386d9a8

Browse files
authored
Merge pull request #2242 from KietChan/MOBILE-3254_integration
MOBILE-3254 ionic: double click on item some time make it open twice
2 parents 086fc95 + 2dd1375 commit 386d9a8

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/components/ion-tabs/ion-tab.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import {
1616
Component, Optional, ElementRef, NgZone, Renderer, ComponentFactoryResolver, ChangeDetectorRef, ErrorHandler, OnInit,
1717
OnDestroy, ViewEncapsulation
1818
} from '@angular/core';
19-
import { Tab, App, Config, Platform, GestureController, DeepLinker, DomController } from 'ionic-angular';
19+
import { Tab, App, Config, Platform, GestureController, DeepLinker, DomController, NavOptions } from 'ionic-angular';
2020
import { TransitionController } from 'ionic-angular/transitions/transition-controller';
2121
import { CoreIonTabsComponent } from './ion-tabs';
22+
import { TransitionDoneFn } from 'ionic-angular/navigation/nav-util';
2223

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

5960
this.parent.remove(this);
6061
}
62+
63+
/**
64+
* Push a page to the navigation stack. this similar to parent NavController, but perform some check to make
65+
* sure one page won't open multiple time.
66+
*/
67+
push(page: any, params?: any, opts?: NavOptions, done?: TransitionDoneFn): Promise<any> {
68+
if (this.isTransitioning()) {
69+
// Try again later, the app is transitioning, this also happen when the page is first loaded.
70+
return new Promise<any>((resolve, reject): void => {
71+
setTimeout(() => {
72+
73+
return this.push(page, params, opts, done).then(resolve, reject);
74+
}, 250);
75+
});
76+
} else {
77+
const previousViews = this.getViews();
78+
if (previousViews.length > 0) {
79+
const previousView = previousViews[previousViews.length - 1];
80+
const previousParam = previousView.getNavParams().data;
81+
82+
// If the view we pushing in have same page's name and identical params, then we won't do anything.
83+
// This is Ionic issue when user clicking too fast on old device or slow internet connection.
84+
if (previousView.name === page && JSON.stringify(previousParam) === JSON.stringify(params)) {
85+
86+
return Promise.resolve();
87+
}
88+
}
89+
90+
return super.push(page, params, opts, done);
91+
}
92+
}
6193
}

0 commit comments

Comments
 (0)