From eeb67f3341337376556c677bb4c1495a93d93fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 31 Mar 2022 13:42:42 +0200 Subject: [PATCH] MOBILE-3833 navbar-buttons: Wait content to be ready before searching --- .../components/navbar-buttons/navbar-buttons.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/core/components/navbar-buttons/navbar-buttons.ts b/src/core/components/navbar-buttons/navbar-buttons.ts index 8655a1bae..77878e67c 100644 --- a/src/core/components/navbar-buttons/navbar-buttons.ts +++ b/src/core/components/navbar-buttons/navbar-buttons.ts @@ -86,7 +86,7 @@ export class CoreNavBarButtonsComponent implements OnInit, OnDestroy { } /** - * Component being initialized. + * @inheritdoc */ async ngOnInit(): Promise { try { @@ -128,7 +128,7 @@ export class CoreNavBarButtonsComponent implements OnInit, OnDestroy { } } catch (error) { // Header not found. - this.logger.warn(error); + this.logger.error(error); } } @@ -199,13 +199,20 @@ export class CoreNavBarButtonsComponent implements OnInit, OnDestroy { */ protected async searchHeader(): Promise { await CoreDom.waitToBeInDOM(this.element); - let parentPage: HTMLElement | null = this.element; + while (parentPage && parentPage.parentElement) { - // Get the next parent page. + const content = parentPage.closest('ion-content'); + if (content) { + // Sometimes ion-page class is not yet added by the ViewController, wait for content to render. + await content.componentOnReady(); + } + parentPage = parentPage.parentElement.closest('.ion-page'); + // Check if the page has a header. If it doesn't, search the next parent page. const header = parentPage?.querySelector(':scope > ion-header'); + if (header && getComputedStyle(header).display !== 'none') { return header; }