Nick
Nick

Reputation: 4248

Android Chrome touch objects don't persist between events

I've developed a web app which has some touch handling code built in. On touch down, it saves a reference to the changedTouches in the event. On touch up, it iterates through the changedTouches and tries to match them to a stored touch object from the touchDown event, signaling the end of a touch. It seems that the touch objects are not the same across the two events though, meaning I cannot match up the touches. The app works great in iOS, and in Safari and Chrome on the desktop with some touch event simulation. Just seems to be a problem in Chrome on Android.

Here's an example: jsFiddle

Upvotes: 0

Views: 563

Answers (2)

ChrisN
ChrisN

Reputation: 41

There is a bug in Chrome for Android where the touches and changedTouches array don't maintain their own unique identifier correctly, unless you apply event.preventDefault() on the touchmove or touchstart event.

This bug affects Chrome for Android in Ice Cream Sandwich and Jelly Bean, and has remained unresolved for over a year. So, the first poster is correct, you should rely on touches[i].identifier or changedTouches[i].identifier, keeping in mind that you must call event.preventDefault() on touchmove or touchstart in order for those identifiers to persist correctly.

http://code.google.com/p/android/issues/detail?id=19827

Upvotes: 4

Boris Smus
Boris Smus

Reputation: 8472

The order of touches in TouchLists is not guaranteed to remain consistent. You should be relying on the touch.identifier instead. Please see the touch events specification.

Upvotes: 3

Related Questions