Delay onClose after swipe

pull/38/head
Lim Chee Aun 2022-12-28 20:02:28 +08:00
rodzic 7200acc2a7
commit 0feee7ea93
1 zmienionych plików z 3 dodań i 1 usunięć

Wyświetl plik

@ -1272,8 +1272,9 @@ function Carousel({ mediaAttachments, index = 0, onClose = () => {} }) {
const [showControls, setShowControls] = useState(false); const [showControls, setShowControls] = useState(false);
useEffect(() => { useEffect(() => {
let swipeTimeout;
let handleSwipe = () => { let handleSwipe = () => {
onClose(); swipeTimeout = setTimeout(onClose, 500);
}; };
if (carouselRef.current) { if (carouselRef.current) {
carouselRef.current.addEventListener('swiped-down', handleSwipe); carouselRef.current.addEventListener('swiped-down', handleSwipe);
@ -1282,6 +1283,7 @@ function Carousel({ mediaAttachments, index = 0, onClose = () => {} }) {
if (carouselRef.current) { if (carouselRef.current) {
carouselRef.current.removeEventListener('swiped-down', handleSwipe); carouselRef.current.removeEventListener('swiped-down', handleSwipe);
} }
clearTimeout(swipeTimeout);
}; };
}, []); }, []);