Skip to content

Instantly share code, notes, and snippets.

@nelsson
Created April 30, 2020 05:11
Show Gist options
  • Select an option

  • Save nelsson/e62450488e1d7d05d72d290702562987 to your computer and use it in GitHub Desktop.

Select an option

Save nelsson/e62450488e1d7d05d72d290702562987 to your computer and use it in GitHub Desktop.
Enable ionViewWillEnter in tabs ionic, https://github.com/ionic-team/ionic/issues/16834
import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { IonTabs } from '@ionic/angular';
import { Subscription } from 'rxjs';
export interface Tab {
tabsWillEnter();
tabsDidEnter();
tabsWillLeave();
tabsDidLeave();
}
@Component({
selector: 'app-payment',
templateUrl: './payment.page.html',
styleUrls: ['./payment.page.scss'],
})
export class PaymentPage implements OnInit, OnDestroy {
@ViewChild('tabs', { static: true }) tabs: IonTabs;
private subs = new Subscription();
private currentTab: Tab;
private tabsDidEnter = false;
constructor() { }
ngOnInit() {
const tabSub = this.tabs.ionTabsDidChange.subscribe(() => {
this.currentTab = this.tabs.outlet.component as Tab;
});
this.subs.add(tabSub);
}
ionViewWillEnter() {
if (this.tabsDidEnter) { // Do not fire on initial load - ionViewWillEnter of child tab will fire
this.currentTab.tabsWillEnter();
}
}
ionViewDidEnter() {
if (this.tabsDidEnter) { // Do not fire on initial load - ionViewDidEnter of child tab will fire
this.currentTab.tabsDidEnter();
}
this.tabsDidEnter = true;
}
ionViewWillLeave() {
this.currentTab.tabsWillLeave();
}
ionViewDidLeave() {
this.currentTab.tabsDidLeave();
}
ngOnDestroy() {
this.subs.unsubscribe();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment