Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move click/tap events to onClick handler to fix bug with double tapping on mobile Chrome #7310

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/core/events/onClick.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
import { now } from '../../shared/utils.mjs';

export default function onClick(e) {
const swiper = this;
const data = swiper.touchEventsData;

if (!swiper.enabled) return;
if (!swiper.allowClick) {
if (swiper.params.preventClicks) e.preventDefault();
if (swiper.params.preventClicksPropagation && swiper.animating) {
e.stopPropagation();
e.stopImmediatePropagation();
}
return;
}

const clickTime = now();
const pathTree = e.path || e.composedPath?.();

swiper.updateClickedSlide((pathTree && pathTree[0]) || e.target, pathTree);
swiper.emit('tap click', e);

if (clickTime - data.lastClickTime < 300) {
swiper.emit('doubleTap doubleClick', e);
}

data.lastClickTime = now();
}
17 changes: 1 addition & 16 deletions src/core/events/onTouchEnd.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { now, nextTick } from '../../shared/utils.mjs';
import { nextTick } from '../../shared/utils.mjs';

export default function onTouchEnd(event) {
const swiper = this;
Expand Down Expand Up @@ -55,21 +55,6 @@ export default function onTouchEnd(event) {
swiper.setGrabCursor(false);
}

// Time diff
const touchEndTime = now();
const timeDiff = touchEndTime - data.touchStartTime;

// Tap, doubleTap, Click
if (swiper.allowClick) {
const pathTree = e.path || (e.composedPath && e.composedPath());
swiper.updateClickedSlide((pathTree && pathTree[0]) || e.target, pathTree);
swiper.emit('tap click', e);
if (timeDiff < 300 && touchEndTime - data.lastClickTime < 300) {
swiper.emit('doubleTap doubleClick', e);
}
}

data.lastClickTime = now();
nextTick(() => {
if (!swiper.destroyed) swiper.allowClick = true;
});
Expand Down
Loading