chrisbateman / impetus

Agnostic utility for adding momentum to anything. It's like iScroll, except not for scrolling. Supports mouse and touch events.
chrisbateman.github.io/impetus
MIT License
487 stars 70 forks source link

Fix additional touches preventing tracking stop, causing jump at next touch down #33

Closed fortinmike closed 5 years ago

fortinmike commented 7 years ago

Considering ev.targetTouches[0] before ev.changedTouches[0] in normalizeEvent() meant that having multiple target touches where the first touch wasn't the same as the one stored by Impetus as the "pointer" would prevent the condition in onUp() from triggering, leaving the internal state in "started" mode (stopTracking() not called) event after all touches had been released. In essence, onUp() was called twice (once for each released touch) but in both cases it tested ev.targetTouches[0] which didn't match the stored "pointer" touch, which was at index 1, causing stopTracking() never to be called.

Unless I'm missing something, as the various event handlers already filter out "unwanted" touches (by storing the first touch's id and checking against that), event normalization can safely consider changed touches only (the touch concerned by the current event), which fixes at least this edge case and makes tracking more reliable when multiple touches are present.

Before (video) After (video)

mpellerin42 commented 7 years ago

+1 for this PR: applying it on our project allowed us to fix a bug. We were exactly in the edge case described by @fortinmike.

fortinmike commented 6 years ago

@chrisbateman Feedback in #13 seems to indicate that this pull request is a keeper. Would you consider reviewing this and merging into master? Currently the impetus library is broken for all its users when using multi-touch.

mperednya commented 6 years ago

+1 for this one.

fortinmike commented 5 years ago

Closing this because I created a new pull request which contains only the relevant changes.