-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
In Android browsers, panning on child of SVG breaks when dragged more than a few pixels #1182
Comments
By digging deeper into the For Android browsers, It turns out that preventing the default "touchmove" event handling on the window will solve this problem for any SVG element on the page, as it will prevent the browser from noticing the touch event and assuming the user is scrolling (which triggers the Here's the straightforward code I used, though notice the need for the specific option:
I will keep this issue listed here, because I think it's something that should be handled (i.e. abstracted away) by HammerJS. For now, I hope people with a similar problem will find this and need less time debugging this one. |
It works and thanks a lot! |
Very help full me, thanks! This problem can reproducing also by PC GoogleChrome(75.0.3770.100) |
いろいろテストしていたところ、 I any try, cant pan twice than. 他の手段として、 I found other method, disabled Angularで2.0.8のhammerjsを使っている場合、以下のようなコードを Below code help you, if you use hammerjs v2.0.8 with Angular. しかし、この手法をとった場合、SVG Elementの移動でtouchmoveによるスクロールの伝播が発生してしまうようです。(HammerConfigうまくやったら回避できたりするのかな?) but, this method cannot without scroll propagation. // ...omit
import { HammerGestureConfig, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
import * as Hammer from 'hammerjs';
// ...omit
const MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
const SUPPORT_TOUCH = 'ontouchstart' in window;
const SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);
const inputClass = SUPPORT_ONLY_TOUCH ? Hammer.TouchInput : SUPPORT_TOUCH ? Hammer.TouchMouseInput : Hammer.MouseInput;
class MyHammerConfig extends HammerGestureConfig {
buildHammer(element: HTMLElement) {
return new Hammer(element, { inputClass });
}
}
@NgModule({
...omit,
providers: [{ provide: HAMMER_GESTURE_CONFIG, useClass: MyHammerConfig }]
}] ref |
@walmink Same problem on iOS and same solution. Thank you very much for posting. I was pleasantly surprised hammer.js even worked on SVG elements when I'm only attaching hammer to the div container but couldn't figure out why pointercancel was being invoked for svg elements when it wasn't if the div contained an image instead. Not to get too off topic but it's nice to see support being started for this very useful package by @squadette. |
See also: https://stackoverflow.com/a/47561100/6535053 I added a script tag in my index.html with |
Just spent some time with a closely related issue - This can happen when drag starts inside one div and ends somewhere else. In my case drag starting in an SVG, but ending outside of it on another div. This can form a browser selection, even if it is not shown because no actual text was selected. Setting "user-select: none" on the SVG prevented this from happening, and I did not get unwanted pointercancel events any more. |
This problem (bug?) is driving me crazy. I can't find any existing issues on it, but maybe I'm missing something. I hope there is some solution, workaround or bug fix.
Problem
In web browsers on Android, panning breaks for elements inside an
<svg>
tag. The same problem does not arise when given a<div>
the same treatment.Reproducing the problem
It's nicely shown by this CodeSandBox example, which you obviously have to run in an Android web browser to see it break.
Here is a video showing the issue on a Nexus 5X.
Description of what's happening:
<svg>
tag (e.g. a<circle>
).panstart
fires correctly.panmove
will also trigger correctly.panmove
will stop firingpanend
will no longer fire (it will if you didn't drag too far)I tested both on an up-to-date Chrome app and a default browser on an old Android. Same effect.
UPDATE 15 June 2018:
See this thread: it seems someone else is experiencing the same problem and dug deeper than I did. He found out that the
pancancel
is being triggered, because apointercancel
is being thrown by the browser. Still not clear why this is happening and how to deal with this.The text was updated successfully, but these errors were encountered: