Skip to content
This repository was archived by the owner on Feb 14, 2020. It is now read-only.

swipe-card: Prevent touchend from reaching cards #41

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
33 changes: 33 additions & 0 deletions swipe-card/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,39 @@ class SwipeCard extends LitElement {
}

this.swiper = new Swiper(this.shadowRoot.querySelector(".swiper-container"), this._parameters);

this._setupTouch();
}

_setupTouch() {
const touchTarget = `.swiper-${this._parameters.touchEventsTarget || 'container'}`;
const touchElement = this.shadowRoot.querySelector(touchTarget);

this._is_swiping = false;

// Re-add 'touchend' event handler in swiper using capture (instead of bubbling), so events
// can be stopped before reaching child elements (i.e. "cards") during touch movements.
// This is not supported otherwise (NB: This is a hack at best).
touchElement.removeEventListener('touchend', this.swiper.onTouchEnd);
touchElement.addEventListener('touchend', this.swiper.onTouchEnd, true);

touchElement.addEventListener(
'touchend',
(ev) => {
if (this._is_swiping) {
ev.stopPropagation();
}
this._is_swiping = false;
},
true
);
touchElement.addEventListener(
'touchmove',
(ev) => {
this._is_swiping = true;
},
true
);
}

_createCardElement(cardConfig) {
Expand Down
6 changes: 3 additions & 3 deletions swipe-card/swipe-card.js

Large diffs are not rendered by default.