Skip to content

Commit

Permalink
Fix: PEN as default TOOL don't work bug (Issue #288)
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmeeedMostafa committed Feb 9, 2023
1 parent 2e6a0a9 commit 3388b6d
Showing 1 changed file with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const PenOptions = ({ t }) => {
pos.offsetX - (designLayer.attrs.xPadding || 0),
pos.offsetY - (designLayer.attrs.yPadding || 0),
];
}, []);
}, [designLayer]);

const handlePointerMove = useCallback(() => {
if (!updatedPen.current.moved) {
Expand Down Expand Up @@ -72,7 +72,7 @@ const PenOptions = ({ t }) => {
},
});
}
}, []);
}, [getPointerPosition]);

const handlePointerUp = useCallback(() => {
if (updatedPen.current.id) {
Expand All @@ -91,23 +91,26 @@ const PenOptions = ({ t }) => {
document.removeEventListener('touchend', handlePointerUp, eventsOptions);
document.removeEventListener('mouseleave', handlePointerUp, eventsOptions);
document.removeEventListener('touchcancel', handlePointerUp, eventsOptions);
}, []);
}, [handlePointerMove]);

const handlePointerDown = useCallback((e) => {
if (e.target.attrs.draggable) {
return;
}
e.evt.preventDefault();
const handlePointerDown = useCallback(
(e) => {
if (e.target.attrs.draggable) {
return;
}
e.evt.preventDefault();

updatedPen.current = { points: getPointerPosition() };
updatedPen.current = { points: getPointerPosition() };

canvasRef.current.on('mousemove touchmove', handlePointerMove);
canvasRef.current.on('mouseleave touchcancel', handlePointerUp);
document.addEventListener('mouseup', handlePointerUp, eventsOptions);
document.addEventListener('touchend', handlePointerUp, eventsOptions);
document.addEventListener('mouseleave', handlePointerUp, eventsOptions);
document.addEventListener('touchcancel', handlePointerUp, eventsOptions);
}, []);
canvasRef.current.on('mousemove touchmove', handlePointerMove);
canvasRef.current.on('mouseleave touchcancel', handlePointerUp);
document.addEventListener('mouseup', handlePointerUp, eventsOptions);
document.addEventListener('touchend', handlePointerUp, eventsOptions);
document.addEventListener('mouseleave', handlePointerUp, eventsOptions);
document.addEventListener('touchcancel', handlePointerUp, eventsOptions);
},
[getPointerPosition, handlePointerMove, handlePointerUp],
);

useEffect(() => {
canvasRef.current = designLayer?.getStage();
Expand All @@ -120,7 +123,7 @@ const PenOptions = ({ t }) => {
canvasRef.current.off('mousedown touchstart', handlePointerDown);
}
};
}, []);
}, [designLayer]);

return (
<AnnotationOptions
Expand Down

0 comments on commit 3388b6d

Please sign in to comment.