-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Bug]: Touch events are not being captured on the mobile device. #8849
Comments
similar situation, touch does not work on the phone |
+1 |
same probelm, touch event dosenot work |
+1 |
+1 |
did you try to use the pointer events instead of touch?
when initializing canvas. the touch start event should fire whit enablePointerEvents: false only, while the pointer events will change the mouse events into pointerdown, pointerup and so on. |
hey @asturur
I have to add support zoom and pan for touch devices. but I'm using fabricJs v5.3.0 in Angular (Typescript). I read your comment about
You can test it on stackblitz |
Touch events does not fire with fabricjs v5.3.0. Guys, Do we have any solution or workaround for this issue? |
@Jogii, I just added a layer of divs on top of the fabric and transferred all touch action events with code |
@timfrio I have to add support zoom and pan for touch devices. it is possible? can you share a working sample example? Please check this Demo on stackblitz Zoom Works on Mouse Scroll, and Pan Works With Hold 'Alt' + Mouse Drag (Hold Down the mouse click and move mouse). but Zoom and pan not working for touch devices. Please help me. |
@asturur @kangax @keyurpatel @melchiar @nimworks @ShaMan123 @stefanhayden @vinch |
My plans for fabric are big and wide and can be seen with the list of ~80 open PRs |
#9551 related |
@niawjunior : Can you please show me the code inside hammerCanvas.on('pan') function ? I am able to use hammer js with fabricjs successfully but my panning is not as smooth as it is show in your video. I would greatly appreciate any help on how did you optimized it to work smoothly? |
Hi here for you |
I also previously had this issue. From what I remember, the package from npm was not built with gestures, so in my "scripts": {
...,
"postinstall": "cd node_modules/fabric && npm install && npm run build_with_gestures"
},
|
thats weird, I was expecting fabric to only ship with dist files and not source code |
@Smrtnyk Fabric ships with both code and dist file because of previous building logic. Is that an issue for some procedure? Regarding touch:events in general, touch events should work and touch events are:
and touchcancel that we don't use. if you prevent pointer events you can enable those too. If you are asking for gesture implementations, i don't think those should be part of the core fabric functionality. Is there even a still maintained good gesture library to make an example with? Because we could have a guide for integration yes, but last time i searched i didn't find a library that is used more than the others or that look better. |
What gestures do we need? |
I have implemented like this, may be helpful. import Hammer from "hammerjs";
const minScale = 0.1;
const maxScale = 10;
let zoomScale = 1;
let currentScale = 1;
export const enableZoom = (canvas) => {
canvas.on("mouse:move", onMouseMove);
const hammer = new Hammer(canvas.upperCanvasEl);
hammer.get("pinch").set({ enable: true });
hammer.on("pinch pinchmove", ev => {
currentScale = Math.min(Math.max(minScale, ev.scale * zoomScale), maxScale);
});
hammer.on("pinchend pinchcancel", () => {
zoomScale = currentScale;
});
};
export const disableZoom = (canvas) => {
canvas.off("mouse:move", onMouseMove);
const hammer = new Hammer(canvas.upperCanvasEl);
hammer.get("pinch").set({ enable: false });
hammer.off("pinch pinchmove pinchend pinchcancel");
};
const onMouseMove = (opt) => {
if ((e.type === "touchmove") && (e.touches.length > 1)) {
canvas.zoomToPoint({ x: canvas.width / 2, y: canvas.height / 2 }, currentScale);
return;
}
} |
Guys, please, where did you put those HammerJs scripts ? Can't find my way to make it work. |
@asnyder13 Thanks. This solves the issue for me with 5.3.0. |
There is a bit of confusion here about touch events. |
CheckList
Version
5.3.0
In What environments are you experiencing the problem?
Reactnative Mobile (android and IOS)
Node Version (if applicable)
19.6.0
Link To Reproduction
Using it in react native mobile app and it's private so we can't share the link.
Steps To Reproduce
Hey, I integrated fabric into my project and trying to capture the touch events of canvas but I'm not able to capture any touch event. I'm using
fabric 5.3.0
. I integrated it in react native by injected JS and displaying it by usingreact-native-webview
. Below is my codeIn the above code, I'm using listener to capture the events but logs are not coming whenever I zoom or touch the canvas object on the mobile screen.
My canvas tag is kept like below in the html of webview:
<body><canvas id="canvas" touch-action="none"></canvas></body>
Cdn used: https://cdnjs.cloudflare.com/ajax/libs/fabric.js/5.3.0/fabric.min.js
Expected Behavior
The touch events should be captured whenever I touch the canvas or pinch zoom on it.
Actual Behavior
The touch events are not being captured. However, when I switch the selection property of the canvas to be true, the
selected
event of the canvas object is being listened!Error Message & Stack Trace
No response
The text was updated successfully, but these errors were encountered: