Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swipe* events are not working on Android 4 and Galaxy Nexus unless you suppress touchmove #315

Closed
gianni opened this issue Nov 18, 2011 · 13 comments
Assignees
Milestone

Comments

@gianni
Copy link

gianni commented Nov 18, 2011

Hi,

I have problem with the swipeLeft and swipeRight events with some mobile devices ...
For example with a galaxy s2 and iphone 4 the swipe events function correctly ...
instead, with a galaxy note (android 2.3.4) and a galaxy s the swipe events don't function ...

Could you help me?
Where can i found a list of supported device?

Thanks in advance!

@mislav
Copy link
Collaborator

mislav commented Nov 26, 2011

We don't have a wide range of non iOS devices to test on (I don't have any, for example. @madrobby has a Blackberry Playbook right now). We invite other people to test on their devices, and debug issues that come across.

@gianni
Copy link
Author

gianni commented Nov 28, 2011

Hi Mislav,
In my javascript code i have inserted this line of code :

document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);

that line disables the touchmove event ...
I have checked the zepto library code and i have seen that this event (touchmove) is executed after the touchstart event end before touchend event that are used to calculate the swipe(left/right) event ...

Probably some device are not able to manage correctly the touchmove event ...
i hope this help to fix this bug

@mihar
Copy link

mihar commented Feb 13, 2012

I can confirm that swipe* events are not working on Android 4 and Galaxy Nexus unless you suppress touchmove with

document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);

as you do in your touch test file.

But that disables the scrolling as well.

Works in iOS in both cases, though.

@ghost ghost assigned madrobby Apr 5, 2012
@sergiolopes
Copy link

Same problem here on Galaxy S II running ICS using both Android 4 stock browser and Chrome Mobile Beta.

@itmuse
Copy link

itmuse commented Sep 8, 2012

Change the touch.js module code with:

...

}).bind('touchmove', function(e){
  cancelLongTap()
  touch.x2 = e.touches[0].pageX
  touch.y2 = e.touches[0].pageY
// If touch horizontal then prevents the event and it will suppress scrolling.
  if(touch.x2 && Math.abs(touch.x1 - touch.x2) > 10)
    e.preventDefault()
}).bind('touchend', function(e){

...

It can work well on Galaxy S II running ICS using both Android 4 stock browser and Chrome Mobile Beta.

@elgerlambert
Copy link
Contributor

I can confirm @itmuse's suggestion works! I'd like to suggest the following tweaks though.

      if (navigator.userAgent.match(/Android/i) &&
          Math.abs(touch.x1 - touch.x2) > 10)
            e.preventDefault()

Tested on:

  • iOS 5.1.1 - Safari & Chrome (iphone4)
  • Android 2.3.6 - Default (galaxy s)
  • Android 4.0.3 - Default & Chrome (galaxy s II)

There is no need to check for touch.x2 here, because touchmove has surely happend and therefore touch.x2 must have been set.

I also added a check so that this fix is only applied to Android (since other devices don't need it) credit to @oklai's as the code used is from his PR #524 related to the same problem.

The great thing about @itmuse's fix (with my tweaks) is that it only hinders the ability to scroll (on Android) when the user has shown clear intent to swipe.

An Android issue related to this bug has existed since Nov 6, 2009 yet the problem persists - even in their new Chrome browser (source).

Fixing this problem through Zepto would -in my opinion- add a lot of value!

@mledoze
Copy link
Contributor

mledoze commented Oct 5, 2012

I confirm that @itmuse fix works. Tested on Samsung Galaxy S3 (android v4.0.4) and Samsung Galaxy Note (android v2.3.6).

@paulfairless
Copy link

I can add that @itmuse fix helps considerably for iPhone5 IOS 6.0.1 also

@Saturate
Copy link

Saturate commented Dec 4, 2012

@itmuse fix tested and works on Nexus 7.

@madrobby
Copy link
Owner

madrobby commented Mar 2, 2013

Fixed in d945672. Thanks for the patch.

@madrobby madrobby closed this as completed Mar 2, 2013
@svapreddy
Copy link

Guys, don't use the above code, I have used it and got my ass kicked. Took so much time in debugging the issue. Finally by removing it fixed the issue. If you enable that scrolling does not work smooth on long lists. I have tested it on my Devices Samsung Galaxy(4.3) and another 4.3 low end device. In both the devices it broke the scrolling. But it fixed the swipe issue but broke the scrolling. Hope this helps and sorry if I am wrong somewhere.

@songhlc
Copy link

songhlc commented May 30, 2014

@svapreddy
i am also have the same problem.
after use the above code,the scorlling work so bad that i have to find other method

@ShirlyFE
Copy link

@songhlc
have you got a good method to fix the bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests