Page 1 of 1

Fix for lost Swipe Events on Android 4.4

Posted: Thu Jan 15, 2015 7:13 pm
by Jörn Krüger

I had a fight with appery/jquery mobile about page and swipe on android 4.4. SwipeLeft and SwipeRight where executed on every 4th or 5th try.

The issue is known for JQuery Mobile and most of the other frameworks as well. See https://github.com/jquery/jquery-mobi...

Root Cause is a change in WebView which requires a preventDefault on touchMove Events if the system should be able to identify a swipe. Unfortunately this collides vertical scroll events, so you can scroll a list.

After trying out several solutions like changing horizontalDistanceThreshold on $.event, using hammer.js, quojs and other Swipe Helpers and no success, I'm ended with this solution from https://developer.motorolasolutions.c...

I've added the suggested code from Gerbrand Stap on the "Device Ready" Event on my first Screen.

// Touchmove events are cancelled on Android KitKat when scrolling is possible on the touched element.
// Scrolling is always vertical in our app. Cancel the event when a touchmove is horizontal,
// so that all following touchmove events will be raised normally.
var startLoc = null;
$( "body" ).on( "touchstart", function( e ) {
if( e.originalEvent.touches.length == 1 ) { // one finger touch
// Remember start location.
var touch = e.originalEvent.touches[ 0 ];
startLoc = { x : touch.pageX, y : touch.pageY };
}
} );

$( "body" ).on( "touchmove", function( e ) {
// Only check first move after the touchstart.
if( startLoc ) {
var touch = e.originalEvent.touches[ 0 ];
// Check if the horizontal movement is bigger than the vertical movement.
if( Math.abs( startLoc.x - touch.pageX )
Math.abs( startLoc.y - touch.pageY ) ) {
// Prevent default, like scrolling.
e.preventDefault();
}
startLoc = null;
}
} );

I did not know, if this is the final solution, but at least my project now can ship with Swipe Scrolling between Pages.


Fix for lost Swipe Events on Android 4.4

Posted: Thu Jan 15, 2015 7:50 pm
by Bruce Stuart

That's awesome... Because I have a customer that's complaining about just the same behavior... Thank you for posting this


Fix for lost Swipe Events on Android 4.4

Posted: Fri Jan 16, 2015 6:53 am
by Evgene Karachevtsev

Hello Jörn,

Thank you for the update! Sure this info will be useful for other users.


Fix for lost Swipe Events on Android 4.4

Posted: Fri Jan 16, 2015 3:24 pm
by Shawn

Awesome fix! Thanks Jorn


Fix for lost Swipe Events on Android 4.4

Posted: Fri Jan 16, 2015 3:29 pm
by Shawn

Hi Evgene

I think it would be great to collect some of these fixes and others like fastkey patch etc under a section 'Optimising UI for your Mobile App' to make these JQM Apps more slick because at the moment compared to native apps they are very sluggish.


Fix for lost Swipe Events on Android 4.4

Posted: Fri Jan 16, 2015 3:47 pm
by Ihor Didevych

Hi Shawn,

Great idea! Noted with thanks!


Fix for lost Swipe Events on Android 4.4

Posted: Thu Apr 16, 2015 8:48 pm
by Oscar Machuca

Thanks Jörn, I have the same problem and was very difficult to find an asswer to fix this issue.


Fix for lost Swipe Events on Android 4.4

Posted: Sat Jul 25, 2015 6:49 am
by Sandeep Singh

Its an awesome fix, Man you save me and my job too. Thank You very much


Fix for lost Swipe Events on Android 4.4

Posted: Thu Dec 03, 2015 1:15 pm
by Maik Schindler

Hi Jörn,

thank you very much for that fix.

To detect swipe up and down I found this solution

http://jsfiddle.net/Q3d9H/1/


Fix for lost Swipe Events on Android 4.4

Posted: Wed May 25, 2016 1:23 pm
by Born Smart

I had swipe issue on lenovo tablet (android 4.4).
Issue fixed for the device.
+1 for the solution.