Skip to content

Commit ba9e7b3

Browse files
committed
fix(tabs): ionChange event is dispatched after the switch
1 parent 0b2cf62 commit ba9e7b3

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

src/components/tabs/tabs.ts

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -384,38 +384,34 @@ export class Tabs extends Ion implements AfterViewInit {
384384
// it's possible the tab is only for opening modal's or signing out
385385
// and doesn't actually have content. In the case there's no content
386386
// for a tab then do nothing and leave the current view as is
387-
if (!selectedTab.root) {
388-
selectedTab.ionSelect.emit(selectedTab);
389-
this.ionChange.emit(selectedTab);
390-
return;
391-
}
392-
393-
// At this point we are going to perform a page switch
394-
// Let's fire willLeave in the current tab page
395-
let currentPage: ViewController;
396-
if (currentTab) {
397-
currentPage = currentTab.getActive();
398-
currentPage && currentPage._willLeave(false);
399-
}
387+
if (selectedTab.root) {
388+
// At this point we are going to perform a page switch
389+
// Let's fire willLeave in the current tab page
390+
var currentPage: ViewController;
391+
if (currentTab) {
392+
currentPage = currentTab.getActive();
393+
currentPage && currentPage._willLeave(false);
394+
}
400395

401-
// Fire willEnter in the new selected tab
402-
const selectedPage = selectedTab.getActive();
403-
selectedPage && selectedPage._willEnter();
396+
// Fire willEnter in the new selected tab
397+
const selectedPage = selectedTab.getActive();
398+
selectedPage && selectedPage._willEnter();
404399

405-
// Let's start the transition
406-
opts.animate = false;
407-
selectedTab.load(opts, () => {
408-
if (opts.updateUrl !== false) {
409-
this._linker.navChange(DIRECTION_SWITCH);
410-
}
411-
this._tabSwitchEnd(selectedTab, selectedPage, currentPage);
412-
});
413-
}
400+
// Let's start the transition
401+
opts.animate = false;
402+
selectedTab.load(opts, () => {
403+
if (opts.updateUrl !== false) {
404+
this._linker.navChange(DIRECTION_SWITCH);
405+
}
406+
this._tabSwitchEnd(selectedTab, selectedPage, currentPage);
407+
});
408+
}
414409

415-
_tabSwitchEnd(selectedTab: Tab, selectedPage: ViewController, currentPage: ViewController) {
416410
selectedTab.ionSelect.emit(selectedTab);
417411
this.ionChange.emit(selectedTab);
412+
}
418413

414+
_tabSwitchEnd(selectedTab: Tab, selectedPage: ViewController, currentPage: ViewController) {
419415
// Update tabs selection state
420416
const tabs = this._tabs;
421417
let tab: Tab;

0 commit comments

Comments
 (0)