January 18, 2011

Android: touchmove event bug

touchmove events in Android web browsers have a really serious bug. If you don't include the following code, the touchmove event will fire once, but not again until you're done moving your touch, which utterly kills the usefulness of the touchmove event. It's a weird one, and may very well break more advanced touch logic that works on iOS. But if you preventDefault() on the touchstart event, your touchmove will function as expected.
element.addEventListener( "touchstart", function(e){ onStart(e); }, false );
function onStart ( touchEvent ) {
  if( navigator.userAgent.match(/Android/i) ) {
    touchEvent.preventDefault();
  }
}
This bug is documented here:
http://code.google.com/p/android/issues/detail?id=5491

and is probably not entirely unrelated to my previous post about weird Android Touch event behavior:
http://uihacker.blogspot.com/2010/10/android-bug-miss-drag-as-we-are-waiting.html

4 comments:

  1. thanks a lot, used this code now, it works well.

    ReplyDelete
  2. If it's useful for someone...
    Samsung galaxy Tab GT-P3100 with Android 4.0.4
    has a lot of problems in Phonegap...

    -Slide transitions blanking...
    -Touch events delays (worst than ever) with the message:
    NO_FAST_DRAW=false
    V/webview(24354): singleCursorHandlerTouchEvent
    getEditableSupport FASLE
    There is no way to prevent the delays, nor with event.preventdefault , NOTHING TO DO....

    The same application, exactly the same, the same device, but wiith Android 4.0.3, WORKS PERFECTLY!!!

    So, avoid upgrading Android version!
    Waiting to Jelly Bean to make the application working (HOPE FOR IT)
    or else.....







    ReplyDelete