Created
April 30, 2020 05:11
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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