Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion core/src/components/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getIonMode } from '../../global/ionic-global';
})
export class App implements ComponentInterface {
private focusVisible?: FocusVisibleUtility;
private tapClickCleanup?: () => void;
private loadTimeout?: ReturnType<typeof setTimeout> | undefined;

@Element() el!: HTMLElement;
Expand All @@ -23,7 +24,7 @@ export class App implements ComponentInterface {
this.rIC(async () => {
const isHybrid = isPlatform(window, 'hybrid');
if (!config.getBoolean('_testing')) {
import('../../utils/tap-click').then((module) => module.startTapClick(config));
import('../../utils/tap-click').then((module) => (this.tapClickCleanup = module.startTapClick(config)));
}
if (config.getBoolean('statusTap', isHybrid)) {
import('../../utils/status-tap').then((module) => module.startStatusTap());
Expand Down Expand Up @@ -65,6 +66,14 @@ export class App implements ComponentInterface {
if (this.loadTimeout) {
clearTimeout(this.loadTimeout);
}
if (this.focusVisible) {
this.focusVisible.destroy();
this.focusVisible = undefined;
}
if (this.tapClickCleanup) {
this.tapClickCleanup();
this.tapClickCleanup = undefined;
}
}

/**
Expand Down
22 changes: 20 additions & 2 deletions core/src/utils/tap-click/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import { doc } from '@utils/browser';
import type { Config } from '../../interface';
import { pointerCoord } from '../helpers';

export const startTapClick = (config: Config) => {
let currentTapClickCleanup: (() => void) | undefined;

export const startTapClick = (config: Config): (() => void) => {
if (doc === undefined) {
return;
return () => {};
}

currentTapClickCleanup?.();

let lastActivated = 0;

let activatableEle: HTMLElement | undefined;
Expand Down Expand Up @@ -137,6 +141,20 @@ export const startTapClick = (config: Config) => {
* ion-content's scroll events.
*/
doc.addEventListener('pointercancel', cancelActive, true);

const cleanup = () => {
doc.removeEventListener('ionGestureCaptured', cancelActive);
doc.removeEventListener('pointerdown', pointerDown, true);
doc.removeEventListener('pointerup', pointerUp, true);
doc.removeEventListener('pointercancel', cancelActive, true);
if (currentTapClickCleanup === cleanup) {
currentTapClickCleanup = undefined;
}
};

currentTapClickCleanup = cleanup;

return cleanup;
};

// TODO(FW-2832): type
Expand Down
Loading