From b1dad1ef64a200c3e9fd0ebb55065d6530a0cd00 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 17 Mar 2022 12:23:50 +0100 Subject: [PATCH] MOBILE-3153 usertours: Silence back button --- .../usertours/components/user-tour/user-tour.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/core/features/usertours/components/user-tour/user-tour.ts b/src/core/features/usertours/components/user-tour/user-tour.ts index 0f0e3d2a1..65f6e63dd 100644 --- a/src/core/features/usertours/components/user-tour/user-tour.ts +++ b/src/core/features/usertours/components/user-tour/user-tour.ts @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { BackButtonEvent } from '@ionic/core'; import { AfterViewInit, Component, ElementRef, EventEmitter, HostBinding, Input, Output, ViewChild } from '@angular/core'; import { CorePromisedValue } from '@classes/promised-value'; import { CoreUserToursFocusLayout } from '@features/usertours/classes/focus-layout'; @@ -22,6 +23,7 @@ import { AngularFrameworkDelegate } from '@singletons'; import { CoreComponentsRegistry } from '@singletons/components-registry'; const ANIMATION_DURATION = 200; +const USER_TOURS_BACK_BUTTON_PRIORITY = 100; /** * User Tour wrapper component. @@ -54,6 +56,7 @@ export class CoreUserToursUserTourComponent implements AfterViewInit { private element: HTMLElement; private wrapperTransform = ''; private wrapperElement = new CorePromisedValue(); + private backButtonListener?: (event: BackButtonEvent) => void; constructor({ nativeElement: element }: ElementRef) { this.element = element; @@ -94,6 +97,16 @@ export class CoreUserToursUserTourComponent implements AfterViewInit { // Show tour. this.active = true; + document.addEventListener( + 'ionBackButton', + this.backButtonListener = ({ detail }) => detail.register( + USER_TOURS_BACK_BUTTON_PRIORITY, + () => { + // Silence back button. + }, + ), + ); + await this.playEnterAnimation(); } @@ -111,6 +124,7 @@ export class CoreUserToursUserTourComponent implements AfterViewInit { acknowledge && CoreUserTours.acknowledge(this.id), ]); + this.backButtonListener && document.removeEventListener('ionBackButton', this.backButtonListener); this.afterDismiss.emit(); }