Skip to content
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

Unable to draw on Android Chrome Browser #36

Closed
Ben76 opened this issue Oct 21, 2017 · 8 comments
Closed

Unable to draw on Android Chrome Browser #36

Ben76 opened this issue Oct 21, 2017 · 8 comments
Labels
Milestone

Comments

@Ben76
Copy link

Ben76 commented Oct 21, 2017

I have a canvas in a Bootstrap Modal.

Works perfectly well on a PC; Not working on Android phone

Used to work well until Chrome released a new version for Android. (on 18th Oct)

Even now, if canvas placed directly on form, it works. Doesn't work when placed in Modal.

@jakubfiala
Copy link
Owner

@Ben76 thanks for submitting the issue. Can you see any errors being thrown in the console? Alternatively, can you create a codepen/jsbin that demonstrates the issue?

@jakubfiala jakubfiala added the bug label Oct 21, 2017
@bencergazda
Copy link
Contributor

bencergazda commented Nov 14, 2018

@Ben76 @jakubfiala I was having the same issue. In my case, it occured only when we needed to scroll downwards the page to the canvas. In this situation, the scrollTop gets added to the mouse position when drawing (see + document.documentElement.scrollLeft in src/atrament.js#L31). Like this, if we scroll down for 10px, and the start painting, the drawing appears 10px under the mouse cursor/touch point.

See: https://codepen.io/bencergazda/full/OapvVL/

I did a quick test with removing the addition of document.documentElement.scrollLeft. This fixes the issue on Mobile Chrome, and looks like not causing problems in other browsers (Firefox, Desktop Chrome, Mobile Safari)

I can make a pull request with a fix.

@jakubfiala
Copy link
Owner

thanks for submitting the PRs @bencergazda – and sorry I'm getting to this late!

both PRs are looking good – going to approve & merge, then test the changes and publish

@jakubfiala
Copy link
Owner

this is now resolved in #39

@viettq1986
Copy link

Hello, I get the same stuck. Can you please check my app.
I can draw perfect on desktop and chrome simulator on desktop and main browser of android. But I can's draw correct on android chrome. It seem i get incorrect coordinate on touch

My app: https://zcolorqa.azurewebsites.net/

Many thanks

@jakubfiala
Copy link
Owner

@viettq1986 thanks for reporting the issue. Could you please let me know how I can replicate the issue in your app? I'm having trouble finding the place where Atrament is used.

Also, what version of Android (and Chrome) are you using?

@jakubfiala jakubfiala reopened this Nov 1, 2020
@viettq1986
Copy link

@viettq1986 thanks for reporting the issue. Could you please let me know how I can replicate the issue in your app? I'm having trouble finding the place where Atrament is used.

Also, what version of Android (and Chrome) are you using?

Hello, Sorry for your Atrament.

Please see my step by step:

image

image

image

image

I am using lasted android chrome version

image

My function for get mouse and touch coordinates
getCoordinate = (e, canvas) => {
let coordinate = {
x: 0,
y: 0
};

if (e.touches && e.touches.length > 0) {
let touch = e.touches[0]; //Get the information for finger #1
let rect = canvas.getBoundingClientRect();

//coordinate.x = Math.floor((touch.pageX - rect.left) * (canvas.width / rect.width));
//coordinate.y = Math.floor((touch.pageY - rect.top) * (canvas.height / rect.height));

coordinate.x = Math.floor((touch.pageX - rect.left) * (canvas.width / rect.width));
coordinate.y = Math.floor((touch.pageY - rect.top) * (canvas.height / rect.height));

let matrix = canvas.getContext("2d").getTransform();
let iMatrix = matrix.invertSelf();

coordinate = applyToPoint(iMatrix, coordinate);

} else {
if (e.offsetX) {
coordinate.x = e.offsetX;
coordinate.y = e.offsetY;
} else if (e.layerX) {
coordinate.x = e.layerX;
coordinate.y = e.layerY;
} else if (e.clientX) {
coordinate.x = e.clientX;
coordinate.y = e.clientY;
}
}

return coordinate;
}

Thank you very much

@jakubfiala jakubfiala added this to the 4.0.0 milestone Jan 11, 2024
@jakubfiala
Copy link
Owner

@viettq1986 I believe your issue might be solved in v4.0.0 - please feel free to reopen if the issue occurs again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants