Touch move getting stuck Ignored attempt to cancel a touchmove
The event must be cancelable
. Adding an if
statement solves this issue.
if (e.cancelable) { e.preventDefault();}
In your code you should put it here:
if (this.isSwipe(swipeThreshold) && e.cancelable) { e.preventDefault(); e.stopPropagation(); swiping = true;}
I had this problem and all I had to do is return true
from touchend and the warning went away.
I know this is an old post but I had a lot of issues trying to solve this and I finally did so I wanted to share.
My issue was that I was adding an event listener within the ontouchstart and removing it in the ontouchend functions - something like this
function onTouchStart() { window.addEventListener("touchmove", handleTouchMove, { passive: false });}function onTouchEnd() { window.removeEventListener("touchmove", handleTouchMove, { passive: true });}function handleTouchMove(e) { e.preventDefault();}
For some reason adding it removing it like this was causing this issue of the event randomly not being cancelable. So to solve this I kept the listener active and toggled a boolean on whether or not it should prevent the event - something like this:
let stopScrolling = false;window.addEventListener("touchmove", handleTouchMove, { passive: false});function handleTouchMove(e) { if (!stopScrolling) { return; } e.preventDefault();}function onTouchStart() { stopScrolling = true;}function onTouchEnd() { stopScrolling = false;}
I was actually using React so my solution involved setting state, but I've simplified it for a more generic solution. Hopefully this helps someone!