Android drag gesture (ionic.onGesture)

The drag event works like a charm on iOS, but not on Android. The only way to drag an element is doing a double tap and hold, on iOS just a single tap and hold (as should be).

Suggestions? Do you think it’s a bug?

I just used this snippet from the angularjs doc and replaced mousedown with dragstart, mousemove with drag and mouseup with dragend.

As wrote it’s ok on iOS!


What version of android are you testing this on?

Latest version: KitKat 4.4.2

hmm, do you mind posting a sample of your code? Or even a codepen?


directive('draggable', function($document, $timeout) {
  return function(scope, element, attr) {
    var startX = 0, startY = 0, x = 0, y = 0, width =0, elementW = 0, elementH = 0;
    $timeout(function() {
      elementW = element.prop('clientWidth');
      elementH = element.prop('clientHeight');

    element.on('dragstart', function(event) {
      // Prevent default dragging of selected content
      startX = - x;
      startY = - y;
      $document.on('drag', move);
      $document.on('dragend', release);

    function move(event) {
      y = - startY;
      x = - startX;
      if (x >= 0 && x <= (parentWidth-elementW)) {
          left:  x + 'px'
      if (y >= 0 && y <= parentHeight-elementH) {
          top:  y + 'px'

    function release() {
      $document.unbind('drag', move);
      $document.unbind('dragend', release);

I take the parentWidth and parentHeight from another directive.

I’m trying to implement it but because its only a partial of your code, I’m having some difficulties. Mind putting a codepen together, then I can transfer it to an android device?

Ok, I’ve tried to extract the code from my app. Maybe it’s a bit buggy… but should work.


Do you actually have a side menu in your app? I installed in on Android 4.1 and was able to drag it right away but, once I removed the sidemenu

yep, I have a side menu… but in the view where I use the draggable directive I’ve disabled the drag for the side menu… like the codepen.

So it’s a conflict with the sidemenu. Do you think it’s a bug?

It could be. I know there was some work done for android to resolve some dragging issues with the side menu. I’ll open an issue for this just to be sure.

Ok thanks! maybe link also the github issue so I can track it!

@mhartington : I’ve tested my app without the sidemenu and on Android I have the same problem.

any news here? I’m also facing this problem.

I know this is kind of an old post, but for anyone still looking I will share my experience with draggable elements on mobile phones, although this doesn’t seem to be the issue here. I had a similar problem, where you had to double tap the element to get it to drag. For me the solution was to disable the scroll on the draggable elements or even the parent (container) of those elements, because that would intervene and trigger before the drag.

1 Like