From cbb69db301ada5b78f8447859dbd29b80029016f Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 16 Jun 2021 12:09:05 +0200 Subject: [PATCH] MOBILE-3320 core: Fix hide tabs issues in SCORM and H5P --- .../mod/h5pactivity/components/index/index.ts | 40 ++++++++++++++++--- src/addons/mod/scorm/pages/player/player.ts | 18 ++++++++- .../course/classes/main-activity-page.ts | 14 +++++++ .../course/classes/main-resource-component.ts | 14 +++++++ 4 files changed, 78 insertions(+), 8 deletions(-) diff --git a/src/addons/mod/h5pactivity/components/index/index.ts b/src/addons/mod/h5pactivity/components/index/index.ts index 0f76adba3..e2f69620e 100644 --- a/src/addons/mod/h5pactivity/components/index/index.ts +++ b/src/addons/mod/h5pactivity/components/index/index.ts @@ -80,6 +80,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv hasOffline = false; isOpeningPage = false; + protected listeningResize = false; protected fetchContentDefaultError = 'addon.mod_h5pactivity.errorgetactivity'; protected syncEventName = AddonModH5PActivitySyncProvider.AUTO_SYNCED; protected site: CoreSite; @@ -372,8 +373,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv CoreCourse.checkModuleCompletion(this.courseId, this.module.completiondata); - window.addEventListener('resize', this.contentResized.bind(this)); - this.contentResized(); + this.setResizeListener(); } /** @@ -488,6 +488,19 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv } } + /** + * Set the resize listener if needed. + */ + setResizeListener(): void { + if (!this.playing || this.listeningResize) { + return; + } + + this.listeningResize = true; + window.addEventListener('resize', this.contentResized.bind(this)); + this.contentResized(); + } + /** * On content resize, change visibility of the main menu: show on portrait and hide on landscape. */ @@ -495,6 +508,25 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv this.mainMenuPage.changeVisibility(Platform.isPortrait()); } + /** + * @inheritdoc + */ + ionViewDidEnter(): void { + this.setResizeListener(); + } + + /** + * @inheritdoc + */ + ionViewWillLeave(): void { + this.mainMenuPage.changeVisibility(true); + + if (this.listeningResize) { + this.listeningResize = false; + window.removeEventListener('resize', this.resizeFunction); + } + } + /** * Component destroyed. */ @@ -503,10 +535,6 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv this.observer?.off(); window.removeEventListener('message', this.messageListenerFunction); - - if (this.playing) { - window.removeEventListener('resize', this.resizeFunction); - } } } diff --git a/src/addons/mod/scorm/pages/player/player.ts b/src/addons/mod/scorm/pages/player/player.ts index fccabab23..c24a3d9fd 100644 --- a/src/addons/mod/scorm/pages/player/player.ts +++ b/src/addons/mod/scorm/pages/player/player.ts @@ -533,6 +533,22 @@ export class AddonModScormPlayerPage implements OnInit, OnDestroy { })); } + /** + * @inheritdoc + */ + ionViewDidEnter(): void { + if (this.scorm && this.scorm.popup) { + this.mainMenuPage.changeVisibility(false); + } + } + + /** + * @inheritdoc + */ + ionViewWillLeave(): void { + this.mainMenuPage.changeVisibility(true); + } + /** * Component being destroyed. */ @@ -549,8 +565,6 @@ export class AddonModScormPlayerPage implements OnInit, OnDestroy { this.goOfflineObserver?.off(); }, 500); - this.mainMenuPage.changeVisibility(true); - // Unblock the SCORM so it can be synced. CoreSync.unblockOperation(AddonModScormProvider.COMPONENT, this.scorm.id, 'player'); } diff --git a/src/core/features/course/classes/main-activity-page.ts b/src/core/features/course/classes/main-activity-page.ts index 8d1ce25c9..4c66ba3b0 100644 --- a/src/core/features/course/classes/main-activity-page.ts +++ b/src/core/features/course/classes/main-activity-page.ts @@ -64,4 +64,18 @@ export class CoreCourseModuleMainActivityPage