From 455b78d98f3cff1fbe50d4f6cbd5725f81197b7b Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 22 May 2019 09:07:04 +0200 Subject: [PATCH] MOBILE-3039 core: Wait a bit before displaying loading modal --- src/core/course/providers/default-format.ts | 5 ++++- src/providers/utils/dom.ts | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/core/course/providers/default-format.ts b/src/core/course/providers/default-format.ts index b445158a9..e03341376 100644 --- a/src/core/course/providers/default-format.ts +++ b/src/core/course/providers/default-format.ts @@ -167,7 +167,10 @@ export class CoreCourseFormatDefaultHandler implements CoreCourseFormatHandler { Object.assign(params, { course: course }); if (navCtrl) { - return navCtrl.push('CoreCourseSectionPage', params); + // Don't return the .push promise, we don't want to display a loading modal during the page transition. + navCtrl.push('CoreCourseSectionPage', params); + + return Promise.resolve(); } else { // Open the course in the "phantom" tab. this.loginHelper = this.loginHelper || this.injector.get(CoreLoginHelperProvider); diff --git a/src/providers/utils/dom.ts b/src/providers/utils/dom.ts index 1af9102c2..4f4fdab17 100644 --- a/src/providers/utils/dom.ts +++ b/src/providers/utils/dom.ts @@ -1250,11 +1250,14 @@ export class CoreDomUtilsProvider { content: text }), dismiss = loader.dismiss.bind(loader); - let isDismissed = false; + let isPresented = false, + isDismissed = false; // Override dismiss to prevent dismissing a modal twice (it can throw an error and cause problems). loader.dismiss = (data, role, navOptions): Promise => { - if (isDismissed) { + if (!isPresented || isDismissed) { + isDismissed = true; + return Promise.resolve(); } @@ -1263,7 +1266,13 @@ export class CoreDomUtilsProvider { return dismiss(data, role, navOptions); }; - loader.present(); + // Wait a bit before presenting the modal, to prevent it being displayed if dissmiss is called fast. + setTimeout(() => { + if (!isDismissed) { + isPresented = true; + loader.present(); + } + }, 40); return loader; }