From bc2e38dece84f924004c31ca7ac3ae2c816d339b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 31 Mar 2022 13:09:59 +0200 Subject: [PATCH] MOBILE-3833 collapsible: Do not init collapsible heading if not needed --- src/addons/mod/folder/pages/index/index.html | 2 +- src/addons/mod/wiki/pages/index/index.html | 2 +- src/core/directives/collapsible-header.ts | 24 ++++++++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/addons/mod/folder/pages/index/index.html b/src/addons/mod/folder/pages/index/index.html index 66812df13..cfafeebb9 100644 --- a/src/addons/mod/folder/pages/index/index.html +++ b/src/addons/mod/folder/pages/index/index.html @@ -1,4 +1,4 @@ - + diff --git a/src/addons/mod/wiki/pages/index/index.html b/src/addons/mod/wiki/pages/index/index.html index fd6c31ce6..c11fb730c 100644 --- a/src/addons/mod/wiki/pages/index/index.html +++ b/src/addons/mod/wiki/pages/index/index.html @@ -1,4 +1,4 @@ - + diff --git a/src/core/directives/collapsible-header.ts b/src/core/directives/collapsible-header.ts index 5bb3d05cf..196a2b1ce 100644 --- a/src/core/directives/collapsible-header.ts +++ b/src/core/directives/collapsible-header.ts @@ -88,7 +88,18 @@ export class CoreCollapsibleHeaderDirective implements OnInit, OnChanges, OnDest /** * @inheritdoc */ - async ngOnInit(): Promise { + ngOnInit(): void { + this.init(); + } + + /** + * Init function. + */ + async init(): Promise { + if (!this.collapsible || this.expandedHeader) { + return; + } + this.initializePage(); await Promise.all([ @@ -104,9 +115,12 @@ export class CoreCollapsibleHeaderDirective implements OnInit, OnChanges, OnDest /** * @inheritdoc */ - ngOnChanges(changes: {[name: string]: SimpleChange}): void { + async ngOnChanges(changes: {[name: string]: SimpleChange}): Promise { if (changes.collapsible) { this.enabled = !CoreUtils.isFalseOrZero(changes.collapsible.currentValue); + + await this.init(); + setTimeout(() => { this.setEnabled(this.enabled); }, 200); @@ -160,8 +174,10 @@ export class CoreCollapsibleHeaderDirective implements OnInit, OnChanges, OnDest // Timeout in case event is never fired. const timeout = window.setTimeout(() => { - this.firstEnter = false; - this.enteredPromise.reject(new Error('[collapsible-header] Waiting for ionViewDidEnter timeout reached')); + if (this.firstEnter) { + this.firstEnter = false; + this.enteredPromise.reject(new Error('[collapsible-header] Waiting for ionViewDidEnter timeout reached')); + } }, 5000); this.resizeListener = CoreDom.onWindowResize(() => {