fix: resolve mobile dual-action translation in HypaV3 modal

This commit is contained in:
Bo26fhmC5M
2025-01-19 09:30:54 +09:00
parent 1b2ea2b15b
commit 0e86d15c62

View File

@@ -292,54 +292,59 @@
}; };
function handleDualAction(node: HTMLElement, params: DualActionParams = {}) { function handleDualAction(node: HTMLElement, params: DualActionParams = {}) {
const state = {
lastTap: 0,
tapTimeout: null as any,
};
const DOUBLE_TAP_DELAY = 300; const DOUBLE_TAP_DELAY = 300;
function handleInteraction(event: Event) { const state = {
if ("ontouchend" in window) { lastTap: 0,
// Mobile environment tapTimeout: null,
const currentTime = new Date().getTime(); };
const tapLength = currentTime - state.lastTap;
if (tapLength < DOUBLE_TAP_DELAY && tapLength > 0) { const handleTouch = (event: TouchEvent) => {
// Double tap detected const currentTime = new Date().getTime();
event.preventDefault(); const tapLength = currentTime - state.lastTap;
clearTimeout(state.tapTimeout); // Cancel the first tap timeout
params.onAlternativeAction?.();
state.lastTap = 0; // Reset state
} else {
// First tap
state.lastTap = currentTime;
// Delayed single tap execution if (tapLength < DOUBLE_TAP_DELAY && tapLength > 0) {
state.tapTimeout = setTimeout(() => { // Double tap detected
if (state.lastTap === currentTime) { event.preventDefault();
// If no double tap occurred clearTimeout(state.tapTimeout); // Cancel the first tap timeout
params.onMainAction?.(); params.onAlternativeAction?.();
} state.lastTap = 0; // Reset state
}, DOUBLE_TAP_DELAY);
}
} else { } else {
// Desktop environment state.lastTap = currentTime; // First tap
if ((event as MouseEvent).shiftKey) { // Delayed single tap execution
params.onAlternativeAction?.(); state.tapTimeout = setTimeout(() => {
} else { if (state.lastTap === currentTime) {
params.onMainAction?.(); // If no double tap occurred
} params.onMainAction?.();
}
}, DOUBLE_TAP_DELAY);
} }
} };
node.addEventListener("click", handleInteraction); const handleClick = (event: MouseEvent) => {
node.addEventListener("touchend", handleInteraction); if (event.shiftKey) {
params.onAlternativeAction?.();
} else {
params.onMainAction?.();
`` }
};
if ("ontouchend" in window) {
// Mobile environment
node.addEventListener("touchend", handleTouch);
} else {
// Desktop environment
node.addEventListener("click", handleClick);
}
return { return {
destroy() { destroy() {
node.removeEventListener("click", handleInteraction); if ("ontouchend" in window) {
node.removeEventListener("touchend", handleInteraction); node.removeEventListener("touchend", handleTouch);
} else {
node.removeEventListener("click", handleClick);
}
clearTimeout(state.tapTimeout); // Cleanup timeout clearTimeout(state.tapTimeout); // Cleanup timeout
}, },
update(newParams: DualActionParams) { update(newParams: DualActionParams) {