Skip to content

Commit c0adeb0

Browse files
committed
Move click/tap events to onClick handler to fix bug with double tapping on mobile chrome.
1 parent fc308b3 commit c0adeb0

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/core/events/onClick.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1+
import { now } from '../../shared/utils.mjs';
2+
13
export default function onClick(e) {
24
const swiper = this;
5+
const data = swiper.touchEventsData;
6+
37
if (!swiper.enabled) return;
48
if (!swiper.allowClick) {
59
if (swiper.params.preventClicks) e.preventDefault();
610
if (swiper.params.preventClicksPropagation && swiper.animating) {
711
e.stopPropagation();
812
e.stopImmediatePropagation();
913
}
14+
return;
1015
}
16+
17+
const clickTime = now();
18+
const pathTree = e.path || e.composedPath?.();
19+
20+
swiper.updateClickedSlide((pathTree && pathTree[0]) || e.target, pathTree);
21+
swiper.emit('tap click', e);
22+
23+
if (clickTime - data.lastClickTime < 300) {
24+
swiper.emit('doubleTap doubleClick', e);
25+
}
26+
27+
data.lastClickTime = now();
1128
}

src/core/events/onTouchEnd.mjs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { now, nextTick } from '../../shared/utils.mjs';
1+
import { nextTick } from '../../shared/utils.mjs';
22

33
export default function onTouchEnd(event) {
44
const swiper = this;
@@ -55,21 +55,6 @@ export default function onTouchEnd(event) {
5555
swiper.setGrabCursor(false);
5656
}
5757

58-
// Time diff
59-
const touchEndTime = now();
60-
const timeDiff = touchEndTime - data.touchStartTime;
61-
62-
// Tap, doubleTap, Click
63-
if (swiper.allowClick) {
64-
const pathTree = e.path || (e.composedPath && e.composedPath());
65-
swiper.updateClickedSlide((pathTree && pathTree[0]) || e.target, pathTree);
66-
swiper.emit('tap click', e);
67-
if (timeDiff < 300 && touchEndTime - data.lastClickTime < 300) {
68-
swiper.emit('doubleTap doubleClick', e);
69-
}
70-
}
71-
72-
data.lastClickTime = now();
7358
nextTick(() => {
7459
if (!swiper.destroyed) swiper.allowClick = true;
7560
});

0 commit comments

Comments
 (0)