From 456784620982e091354e66c92db42f91fe4c7d76 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 15 Jun 2021 18:28:20 +0200 Subject: [PATCH] MOBILE-3320 tabs: Call navigation hooks --- .../components/tabs-outlet/tabs-outlet.ts | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/core/components/tabs-outlet/tabs-outlet.ts b/src/core/components/tabs-outlet/tabs-outlet.ts index 2ccf498e3..1783496b4 100644 --- a/src/core/components/tabs-outlet/tabs-outlet.ts +++ b/src/core/components/tabs-outlet/tabs-outlet.ts @@ -23,7 +23,7 @@ import { ElementRef, SimpleChange, } from '@angular/core'; -import { IonTabs } from '@ionic/angular'; +import { IonTabs, ViewDidEnter, ViewDidLeave } from '@ionic/angular'; import { Subscription } from 'rxjs'; import { CoreUtils } from '@services/utils/utils'; @@ -65,10 +65,11 @@ export class CoreTabsOutletComponent extends CoreTabsBaseComponent; + protected existsInNavigationStack = false; - constructor( - element: ElementRef, - ) { + constructor(element: ElementRef) { super(element); } @@ -110,6 +111,9 @@ export class CoreTabsOutletComponent extends CoreTabsBaseComponent { + this.lastActiveComponent = this.ionTabs?.outlet.component; + }); } /** @@ -127,6 +131,35 @@ export class CoreTabsOutletComponent extends CoreTabsBaseComponent).ionViewDidEnter?.(); + } + + // After the view has entered for the first time, we can assume that it'll always be in the navigation stack + // until it's destroyed. + this.existsInNavigationStack = true; + } + + /** + * @inheritdoc + */ + ionViewDidLeave(): void { + super.ionViewDidLeave(); + + // The `ionViewDidLeave` method is not called on nested outlets unless the active view changes, that's why + // we need to call it manually if the page is leaving and the last active component was not notified. + this.lastActiveComponent?.ionViewDidLeave?.(); + } + /** * Load the tab. * @@ -165,6 +198,8 @@ export class CoreTabsOutletComponent extends CoreTabsBaseComponent