Delay onClose after swipe

This commit is contained in:
Lim Chee Aun 2022-12-28 20:02:28 +08:00
parent 7200acc2a7
commit 0feee7ea93

View file

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