Merge pull request #531 from factman/fix-mask-drawing-on-touch-devices
Fix mask drawing on touch devices
This commit is contained in:
commit
ef1f7a5324
@ -800,6 +800,9 @@ export default function Editor(props: EditorProps) {
|
||||
onMouseDown={onMouseDown}
|
||||
onMouseUp={onCanvasMouseUp}
|
||||
onMouseMove={onMouseDrag}
|
||||
onTouchStart={onMouseDown}
|
||||
onTouchEnd={onCanvasMouseUp}
|
||||
onTouchMove={onMouseDrag}
|
||||
ref={(r) => {
|
||||
if (r && !context) {
|
||||
const ctx = r.getContext("2d")
|
||||
|
@ -181,6 +181,16 @@ export function downloadImage(uri: string, name: string) {
|
||||
|
||||
export function mouseXY(ev: SyntheticEvent) {
|
||||
const mouseEvent = ev.nativeEvent as MouseEvent
|
||||
// Handle mask drawing coordinate on mobile/tablet devices
|
||||
if ('touches' in ev) {
|
||||
const rect = (ev.target as HTMLCanvasElement).getBoundingClientRect();
|
||||
const touches = ev.touches as (Touch & { target: HTMLCanvasElement })[]
|
||||
const touch = touches[0]
|
||||
return {
|
||||
x: (touch.clientX - rect.x) / rect.width * touch.target.offsetWidth,
|
||||
y: (touch.clientY - rect.y) / rect.height * touch.target.offsetHeight,
|
||||
}
|
||||
}
|
||||
return {x: mouseEvent.offsetX, y: mouseEvent.offsetY}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user