bug: Ionic gestures not working
Type: bug
Platform: android 4.4 webview
I haven't tried in iOS "native hybrid", but in phone's browser it works perfectly, even the pinch gesture (at least for Android 4.4 and iOS 7)
I have made an app with a div that has the ionic gestures listeners in it. Then in the top there's another div that says which gestures have been detected.
What happens in the "native" android version:
- touch/tap/double tap/release works OK
- If you do it fast enough*, drag and swipe also works for very little time. Then it gets "released" and then is not working anymore.
- And if you go slowly, right when your finger is leaving the touch-start spot, it gets "released"
- Also, pinch gesture doesn't work at all.
Plunker here: http://plnkr.co/edit/XYrvChZ6o92r94mSt8Qb?p=preview Project zip file: http://www.livewind.org/ionic/gestures.zip
I Tested in many other devices and I found that it only happens in Android 4.4 (Tested in android 4.1, 4.2, 2.3 [with a no-multitouch device, but drag works properly] and iOS 6 and soonish in iOS 7)
Also searching in the forums I found out this post: http://forum.ionicframework.com/t/ionicgesture-not-working-on-device-or-emulator/5992/19 They say they'd open an issue that I can't find. They also say that's happening only in Android 4.4
Isn't this issue a bit important? 1 every 4 androids are 4.4 (see https://developer.android.com/about/dashboards/index.html)... and it looks like Ionic Gestures in these devices don't work at all.
OK I think I found it. Debugging a bit the Chrome vs Native build I found out that in the Native build, the WebView was dispatching "touchcancel" everytime I move my finger from its place.
(Look for this.bindDom(element, ionic.Gestures.EVENT_TYPES[eventType], function bindDomOnTouch(ev) in the bundle)
From this article: https://plus.google.com/+PaulIrish/posts/KTwfn1Y2238, it seems that Chrome (Let me just point that Android 4.4 has a Chrome-based webview) dispatches a "touchcancel" event whenever he finds that a scrolling is happening. Might be this?
Is there any way to fix that?
Nah, now I defenitely found it! yay
1st link: https://developer.android.com/guide/webapps/migrating.html quote in "Handling Touch Events in JavaScript":
"[...] There are a few scenarios where touchcancel will be called, which can cause problems if not received:
-> An element is touched (so touchstart and touchmove are called) and the page is scrolled, causing a touchcancel to be thrown.
-> An element is touched (touchstart is called) but event.preventDefault() is not called, resulting earlier enough that touchcancel is thrown (so WebView assumes you don't want to consume the touch events).
Also, this stackoverflow helped: http://stackoverflow.com/questions/10367854/html5-android-touchcancel
Then, if I put a if(sourceEventType == "touchmove") ev.preventDefault(); right inside this.bindDom(element.... after setting sourceEventType fixes the problem.
Further testing I found out that this "patch" breaks ionic scrolling, so I'm not posting a pull request for it. But then this patch is not really needed if using scroll:
-> With scroll="false", gestures doesn't work unless you apply my patch
-> Without scroll="false", gestures work perfectly, but if you apply my patch then scroll doesn't work.
So the best solution by now is to keep the scroll in the content-view
I think you got it right. It's the same issue that has been draggin' for a while. I opened an issue a while ago but have given up on this: https://github.com/driftyco/ionic/issues/1057 In my app I'm not using scrolling and I'm interested to see your patch/solution.
My "patch" was to put a if(sourceEventType == "touchmove") ev.preventDefault(); right inside this.bindDom(element.... in the ionic bundle after setting sourceEventType, but this breaks the ion-scroll for the whole app, so it's not really useful if you need ion-scroll (for other pages than .
What I did to my app, as a workaround, is to keep the scroll in the content. If your element inside the content is using CSS height: 100%, you will also need to tell the scroll to fill the whole page (with height:100% as well).
Confirmed, we should update our implementation of Hammer.JS. Many gesture events are not firing in Android KitKat
This is actually a duplicate of #1729. Lets continue the discussion there.
Curious why all of these issues are closed? Using ioninc-1.0.0-rc5 I am still seeing this issue for pinch, pinchin, pinchout, transform events on Android 4.4.0 device. When I try on an Android 5.0 device pinch, pinchin, pinchout, and transform are captured flawlessly.
Is there an accepted workaround?
+1
+1 the issue is not fixed in latest v1 release, should we reopen it or just create a new one?
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.