dbltap
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import React, { useEffect, useRef, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { createPortal } from 'react-dom';
|
import { createPortal } from 'react-dom';
|
||||||
import { ArrowLeftIcon, ArrowRightIcon } from '../ui/icons';
|
import { ArrowLeftIcon, ArrowRightIcon } from '../ui/icons';
|
||||||
|
import usePointerTap from '../ui/usePointerTap';
|
||||||
|
|
||||||
const noop = () => {};
|
const noop = () => {};
|
||||||
|
|
||||||
@@ -36,7 +37,6 @@ const PreviewZoomOverlay = ({
|
|||||||
const previouslyFocusedRef = useRef(null);
|
const previouslyFocusedRef = useRef(null);
|
||||||
const visibilityTimerRef = useRef(null);
|
const visibilityTimerRef = useRef(null);
|
||||||
const displayTimerRef = useRef(null);
|
const displayTimerRef = useRef(null);
|
||||||
const clickTimerRef = useRef(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (display?.url) {
|
if (display?.url) {
|
||||||
@@ -89,20 +89,12 @@ const PreviewZoomOverlay = ({
|
|||||||
if (displayTimerRef.current) {
|
if (displayTimerRef.current) {
|
||||||
cancelAnimationFrame(displayTimerRef.current);
|
cancelAnimationFrame(displayTimerRef.current);
|
||||||
}
|
}
|
||||||
if (clickTimerRef.current) {
|
|
||||||
clearTimeout(clickTimerRef.current);
|
|
||||||
clickTimerRef.current = null;
|
|
||||||
}
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsNativeScale(false);
|
setIsNativeScale(false);
|
||||||
setNaturalSize({ width: null, height: null });
|
setNaturalSize({ width: null, height: null });
|
||||||
focusRef.current = null;
|
focusRef.current = null;
|
||||||
if (clickTimerRef.current) {
|
|
||||||
clearTimeout(clickTimerRef.current);
|
|
||||||
clickTimerRef.current = null;
|
|
||||||
}
|
|
||||||
const scrollEl = scrollRef.current;
|
const scrollEl = scrollRef.current;
|
||||||
if (scrollEl) {
|
if (scrollEl) {
|
||||||
scrollEl.scrollLeft = 0;
|
scrollEl.scrollLeft = 0;
|
||||||
@@ -203,13 +195,6 @@ const PreviewZoomOverlay = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!renderBackdrop || !activeDisplay?.url || !portalTarget) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const effectiveDisplay = activeDisplay;
|
|
||||||
const navVisible = Boolean(effectiveDisplay?.canGoPrev || effectiveDisplay?.canGoNext);
|
|
||||||
|
|
||||||
const toggleZoomAtPoint = (clientX, clientY) => {
|
const toggleZoomAtPoint = (clientX, clientY) => {
|
||||||
const img = imageRef.current;
|
const img = imageRef.current;
|
||||||
setIsNativeScale((current) => {
|
setIsNativeScale((current) => {
|
||||||
@@ -228,26 +213,27 @@ const PreviewZoomOverlay = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const pointerTapHandler = usePointerTap({
|
||||||
|
delay: CLICK_DELAY_MS,
|
||||||
|
onSingle: () => {
|
||||||
|
onClose();
|
||||||
|
},
|
||||||
|
onDouble: ({ clientX, clientY }) => {
|
||||||
|
toggleZoomAtPoint(clientX, clientY);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const handleImagePointerDown = (event) => {
|
const handleImagePointerDown = (event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
if (event.button && event.button !== 0) {
|
pointerTapHandler(event);
|
||||||
return;
|
};
|
||||||
}
|
|
||||||
if (event.pointerType === 'touch' && event.isPrimary === false) {
|
if (!renderBackdrop || !activeDisplay?.url || !portalTarget) {
|
||||||
return;
|
return null;
|
||||||
}
|
|
||||||
if (clickTimerRef.current) {
|
|
||||||
clearTimeout(clickTimerRef.current);
|
|
||||||
clickTimerRef.current = null;
|
|
||||||
toggleZoomAtPoint(event.clientX, event.clientY);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clickTimerRef.current = setTimeout(() => {
|
const effectiveDisplay = activeDisplay;
|
||||||
clickTimerRef.current = null;
|
const navVisible = Boolean(effectiveDisplay?.canGoPrev || effectiveDisplay?.canGoNext);
|
||||||
onClose();
|
|
||||||
}, CLICK_DELAY_MS);
|
|
||||||
};
|
|
||||||
const stageClassName = [
|
const stageClassName = [
|
||||||
'preview-zoom__stage',
|
'preview-zoom__stage',
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user