Drag gesture not working properly on mobile device
Hi, I'm trying to use simple drag gesture in my application. Everything works as expected in browser (Chrome v33.0) but when I run it on my mobile device I get only 1 drag event. I'm using ionic (v1.0.0-beta.1) in combination with angularjs(1.2.12). I've created simple project using generator-ionic and added directive test. Here is the directive snippet (just link function):
link: function postLink(scope, element, attrs) {
scope.dragCount = 0;
var dragFn = function (e) {
scope.dragCount++;
console.log(scope.dragCount)
}
scope.$on('$destroy', function () {
$ionicGesture.off(dragGesture, 'drag', dragFn);
});
var dragGesture = $ionicGesture.on('drag', dragFn, element);
}
Directive is in home view:
<ion-view>
<ion-content scroll="false">
<div test>test</div>
</ion-content>
</ion-view>
When I'm running the app on mobile device I'm catching the log messages from directive in Eclipse's LogCat. With this code I get only 1 log message per dragging while in browser it works as expected with multiple log messages.
I've tried to replace <ion-content> with <ion-pane> but I get the same result. It seems to me like some mechanism is blocking or preventing drag gesture event.
If I remove scroll="false" then drag event is working normally on mobile device (I got multiple log messages). But then I have scroll element which I don't need on my homepage and which is interfering with vertical drags that I want to have on my elements.
Has anyone encountered with this kind of behavior? Have I forgot something to initialize for gestures on mobile devices? Does the class "disable-user-behavior" which is added by hammer.js prevent dragging on mobile device?
The mobile device which I use for developing is LG E440 with Android version 4.1.2.
I have also tried the same code on Sony Xperia U with Android version 4.0.4 and on HTC One Android 4.4.2.
It' working properly on Sony Xperia while it's broken on HTC One.
I guess this issue is related to mobile device or Android version.
Any help would be appreciated.
Couple of things to start off with:
- I wouldn't use a separate Angular version. Ionic is built on top of Angular, but bundles a release of Angular that works best with Ionic. So in your index.html, just use ionic.bundle.min.js and get rid of your own version of Angular.
- Ionic also already supports gestures via a built in module called ionicGesture (http://ionicframework.com/docs/api/service/$ionicGesture/). I'm not entirely sure but it could very well be that Hammer.js is conflicting with the built in taps / gestures recognition system that Ionic provides. I would look at using ionicGesture first to see if it supports your needs, and if it doesn't, open an issue for features that ionicGesture doesn't provide at the moment.
Hi Coen, thank you for replying. As you suggested I removed angular definition from index.html and only included bundled version of ionic, ionic.bundle.js. I got the same result, drag event is only triggered once. I wanted to rule out that the configuration of project could be the source of the problem so I created simple project using the guide from http://ionicframework.com/docs/guide. I only added this trivial test directive in which I catch drag gesture. This directive is shown in my last post. I still have the same issue and behavior in which drag event is triggered only once on my mobile devices (LG E440 and HTC One) while in browser everything looks fine.
I'm sorry I wasn't clear about which gesture recognition system I'm using. I'm using $ionicGesture in my project and not the hammer.js. I thought that the $ionicgesture is implementation of hammer.js and that is why wrote it in my last post. So to the be 100% clear here is full declaration of my directive:
angularModule
.directive('test', ["$ionicGesture", function ($ionicGesture) {
return {
restrict: 'A',
scope: {
},
link: function postLink(scope, element, attrs) {
scope.dragCount = 0;
var dragFn = function (e) {
scope.dragCount++;
console.log(scope.dragCount)
}
scope.$on('$destroy', function () {
$ionicGesture.off(dragGesture, 'drag', dragFn);
});
var dragGesture = $ionicGesture.on('drag', dragFn, element);
}
};
}]);
If I put this directive inside <ion-pane></ion-pane> or <ion-content scroll="false"></ion-content> it triggers drag event only once while if I put it in <ion-content></ion-content> the event is triggered multiple times as expected.
There are two opened topics on forum for this problem http://forum.ionicframework.com/t/drag-gesture-not-working-properly-on-mobile-device/2652 http://forum.ionicframework.com/t/ionicgestures-drag-event-called-just-once-in-a-long-drag/845
Ok great, thanks for ruling these things out. In that case the devs or someone with more coding chops than me needs to take a look at it.
I would recommend updating your original issue text with the link to the forum that you just gave, and don't refer to it as an issue. Issues on GitHub are something different from a topic on the forum and your wording makes it look like there was already an issue on GitHub with your problem, which would lead a dev to think there are now two open issues on GitHub for the same problem and that's not the case. There's a post on the forum, and now there's an issue on GitHub.
In general it's good practice to first try to solve your problem with help from others on the forum, and if that doesn't work then open an issue on GitHub.
Testing this out now.
@b8rother I'm getting this too. Interesting.
@adamdbradley any ideas?
tl;dr: problem is with drag event. Desktop gives a drag event constantly while dragging, but mobile (only tested android 4.4) is only giving one update while dragging.
Thanks for pointing this out. Once I get my tap/click refactoring in master, and @tlancina gets the keyboard fixes in we'll take a look at that next. Thanks
I'm having this issue as well when trying to use on Moto X, running android KitKat 4.4.2. It works fine on iphone and desktop, but I am only getting one drag event on my android device. This also happens on a LG G2. I believe the version number is the same as above, but I don't have the phone in front of me (a friend was testing this). Any chance this has been fixed since april 10th?
I've been unable to replicate this, so it may have been fixed indirectly from other issues. If you are still seeing this issue, please create a codepen and describe how to replicate it, and from what device/platform/version this issue can be seen on. Thanks.
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.