material icon indicating copy to clipboard operation
material copied to clipboard

md-swipe not working correctly on chrome for android

Open wolfet opened this issue 9 years ago • 68 comments

Actual Behavior:

  • What is the issue? * On the latest version of Chrome for Android, md-swipe is not working as expected. md-swipe-left is triggered from a swipe in any direction. md-swipe-right, md-swipe-up, and md-swipe-down do not respond.
  • What is the expected behavior? md-swipe-left should respond only to left swipes, and other md-swipe-* directives should respond to their respective directions. CodePen (or steps to reproduce the issue): *
  • CodePen Demo which shows your issue: http://codepen.io/twolfe/pen/pNQBrb
  • Details: This works on chrome desktop, but not chrome for Android version 55.0.2883.91. Open the codepen, http://codepen.io/twolfe/full/pNQBrb/, on an Android phone with the latest Chrome update, or with Chrome DevTools device mode, to see the issue. This issue is showing up on my Pixel XL.

Angular Versions: *

  • Angular Version: 1.5.5
  • Angular Material Version: 1.1.1

Additional Information:

  • Browser Type: * Chrome for Android
  • Browser Version: *55.0.2883.91
  • OS: *Android 7.1.1
  • Stack Traces:

wolfet avatar Dec 15 '16 21:12 wolfet

This can also be repeated in the Chrome DevTools Device Mode

RoniPa avatar Dec 16 '16 06:12 RoniPa

I encountered the same issue on my hybrid Cordova app. Downgrading the Android System Web view from the play store is a workaround for hybrid apps which use web views for now. I hope the issue will be resolved soon.

LohithAnand avatar Dec 16 '16 11:12 LohithAnand

Hi Team, its driving my users crazy. Need some quick fix

mdtjn avatar Dec 17 '16 12:12 mdtjn

@LohithAnand, how to downgrade the Android System Web view from the play store?

imromec avatar Dec 17 '16 13:12 imromec

@imromec Locate the Android System Webview in play store and click on the uninstall button. This will rollback to the version of Webview shipped with the OS.

LohithAnand avatar Dec 20 '16 07:12 LohithAnand

Same problem on main site demo in the Chrome DevTools Device Mode: https://material.angularjs.org/latest/demo/swipe

SlavaSlimmy avatar Dec 21 '16 15:12 SlavaSlimmy

+1

mohammadrafigh avatar Dec 23 '16 00:12 mohammadrafigh

+1 Any workarounds for now?

motabass avatar Dec 23 '16 08:12 motabass

let me mention that issue also appears on Firefox when testing in device mode with touch enabled. it's kind of a normal to high priority issue IMO but there is no attention to it yet...

Update:

I just had a review on code and found that angular material uses initCustomEvent() to make these native events which is deprecated currently, I'm not sure if that's the reason... just shared my findings.

mohammadrafigh avatar Dec 24 '16 16:12 mohammadrafigh

I'm currently building a web app which makes use of sliders extensively. Since I discovered this issue I can't find sleep. Development has slowed down as a result of this feature not working correctly especially in mobile. It work fine on desktop though.

watat83 avatar Dec 25 '16 14:12 watat83

If you are building hybrid app using cordova, then this issue can be resolved by installing cordova crosswalk plugin.

imromec avatar Dec 26 '16 05:12 imromec

Seems that in Chrome Device Mode, in the $mdGestures provider, the touch pointercancel event with properties x and y as 0 is triggered on swipe end. In regular mode the mouse pointerup event is triggered with the x and y properties set to the location where mouse click ended. I believe the issue could have something to do with this.

RoniPa avatar Dec 27 '16 14:12 RoniPa

+1 ... really need a fix for this

duncan1a avatar Dec 30 '16 07:12 duncan1a

Could the issue be here?

function getEventPoint(ev) {
  ev = ev.originalEvent || ev; // support jQuery events
  return (ev.touches && ev.touches[0]) ||
    (ev.changedTouches && ev.changedTouches[0]) ||
    ev;
}

ev.touches and ev.changedTouches are always undefined so ev is always returned.

I'm not sure how ev.touches are supposed to work, but it seems that this is looking for the original event to return. That is compared in updatePointerState() with the current event and direction calculated.

Any ideas on how to get around this?

duncan1a avatar Dec 30 '16 09:12 duncan1a

I believe the issue might be in the missing pageX and pageY properties on the last returned touch event (pointercancel), because the swipe direction gets always calculated towards the upper left corner here:


function updatePointerState(ev, pointer) {
  var point = getEventPoint(ev);
  var x = pointer.x = point.pageX; // point.pageX == 0
  var y = pointer.y = point.pageY; // point.pageY == 0

  pointer.distanceX = x - pointer.startX;
  pointer.distanceY = y - pointer.startY;
  pointer.distance = Math.sqrt(
    pointer.distanceX * pointer.distanceX + pointer.distanceY * pointer.distanceY
  );

  pointer.directionX = pointer.distanceX > 0 ? 'right' : pointer.distanceX < 0 ? 'left' : '';
  pointer.directionY = pointer.distanceY > 0 ? 'down' : pointer.distanceY < 0 ? 'up' : '';

  pointer.duration = +Date.now() - pointer.startTime;
  pointer.velocityX = pointer.distanceX / pointer.duration;
  pointer.velocityY = pointer.distanceY / pointer.duration;
}

As this broke with a Chrome update I believe they changed the browser so that either the pointercancel event data changed or it's the wrong event type to begin with (are we expecting pointerup for example?)

RoniPa avatar Dec 30 '16 09:12 RoniPa

RoniPa, yep, I think you're right. There is pointer.startX, what we need is the finishing point.

This is also messing up scrolling in my sidenav. It triggers the nav to close.

duncan1a avatar Dec 30 '16 10:12 duncan1a

This is a tricky one indeed. The very last event brings no mouse position info and the direction ends up always 'left'. Other touch options are getting a conflict, ng-swipe doesn't seem to trigger, ng-mouseup or down not working for touch move(for a fast manual solution). Isn't this a Chrome error, messing up this event?

Just wanted to add a +1 here.

ginalx avatar Dec 31 '16 12:12 ginalx

+1. This breaks the md-swipe-content in tabs as well. Also the demo is broken and only swipe left works.

mtf2000 avatar Dec 31 '16 17:12 mtf2000

+1 Looking forward to see this fixed soon.

If your development slowed down with this bug like ours, a quick workaround would be using https://github.com/adzialocha/angular-swipe and changing md-swipe-* to ng-swipe-* until this is fixed.

vjku avatar Jan 03 '17 14:01 vjku

Confirmed that angular-swipe does work.

ginalx avatar Jan 03 '17 19:01 ginalx