MOBILE-3153 usertours: Silence back button

main
Noel De Martin 2022-03-17 12:23:50 +01:00
parent 2e473ee55d
commit b1dad1ef64
1 changed files with 14 additions and 0 deletions

View File

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { BackButtonEvent } from '@ionic/core';
import { AfterViewInit, Component, ElementRef, EventEmitter, HostBinding, Input, Output, ViewChild } from '@angular/core'; import { AfterViewInit, Component, ElementRef, EventEmitter, HostBinding, Input, Output, ViewChild } from '@angular/core';
import { CorePromisedValue } from '@classes/promised-value'; import { CorePromisedValue } from '@classes/promised-value';
import { CoreUserToursFocusLayout } from '@features/usertours/classes/focus-layout'; import { CoreUserToursFocusLayout } from '@features/usertours/classes/focus-layout';
@ -22,6 +23,7 @@ import { AngularFrameworkDelegate } from '@singletons';
import { CoreComponentsRegistry } from '@singletons/components-registry'; import { CoreComponentsRegistry } from '@singletons/components-registry';
const ANIMATION_DURATION = 200; const ANIMATION_DURATION = 200;
const USER_TOURS_BACK_BUTTON_PRIORITY = 100;
/** /**
* User Tour wrapper component. * User Tour wrapper component.
@ -54,6 +56,7 @@ export class CoreUserToursUserTourComponent implements AfterViewInit {
private element: HTMLElement; private element: HTMLElement;
private wrapperTransform = ''; private wrapperTransform = '';
private wrapperElement = new CorePromisedValue<HTMLElement>(); private wrapperElement = new CorePromisedValue<HTMLElement>();
private backButtonListener?: (event: BackButtonEvent) => void;
constructor({ nativeElement: element }: ElementRef<HTMLElement>) { constructor({ nativeElement: element }: ElementRef<HTMLElement>) {
this.element = element; this.element = element;
@ -94,6 +97,16 @@ export class CoreUserToursUserTourComponent implements AfterViewInit {
// Show tour. // Show tour.
this.active = true; this.active = true;
document.addEventListener(
'ionBackButton',
this.backButtonListener = ({ detail }) => detail.register(
USER_TOURS_BACK_BUTTON_PRIORITY,
() => {
// Silence back button.
},
),
);
await this.playEnterAnimation(); await this.playEnterAnimation();
} }
@ -111,6 +124,7 @@ export class CoreUserToursUserTourComponent implements AfterViewInit {
acknowledge && CoreUserTours.acknowledge(this.id), acknowledge && CoreUserTours.acknowledge(this.id),
]); ]);
this.backButtonListener && document.removeEventListener('ionBackButton', this.backButtonListener);
this.afterDismiss.emit(); this.afterDismiss.emit();
} }