Jörn Krüger
Posts: 0
Joined: Mon Oct 13, 2014 5:22 am

Fix for lost Swipe Events on Android 4.4

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.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Fix for lost Swipe Events on Android 4.4

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

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Fix for lost Swipe Events on Android 4.4

Hello Jörn,

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

Shawn
Posts: 0
Joined: Sat Jun 21, 2014 11:13 pm

Fix for lost Swipe Events on Android 4.4

Awesome fix! Thanks Jorn

Shawn
Posts: 0
Joined: Sat Jun 21, 2014 11:13 pm

Fix for lost Swipe Events on Android 4.4

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.

Ihor Didevych
Posts: 0
Joined: Wed Nov 19, 2014 7:55 pm

Fix for lost Swipe Events on Android 4.4

Hi Shawn,

Great idea! Noted with thanks!

Oscar Machuca
Posts: 0
Joined: Thu Apr 16, 2015 8:48 pm

Fix for lost Swipe Events on Android 4.4

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

Sandeep Singh
Posts: 0
Joined: Sat Jul 25, 2015 6:49 am

Fix for lost Swipe Events on Android 4.4

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

Maik Schindler
Posts: 0
Joined: Thu Dec 03, 2015 1:15 pm

Fix for lost Swipe Events on Android 4.4

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/

Born Smart
Posts: 0
Joined: Wed May 25, 2016 1:22 pm

Fix for lost Swipe Events on Android 4.4

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

Return to “Issues”