Canvas in draw in now responsie 🚀 (#11876)

This commit is contained in:
Sarthak Sharma 2020-12-15 23:38:09 +05:30 committed by GitHub
parent 1b4bd6f82e
commit bb532d39b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,6 +18,7 @@ import { Button } from '@crayons';
*/
function Draw({ sendCanvasImage }) {
const canvasRef = useRef(null);
const canvasWidth = useRef(null);
const [isDrawing, setIsDrawing] = useState(false);
const [drawColor, setDrawColor] = useState('#F58F8E');
const [coordinates, setCoordinates] = useState({});
@ -72,7 +73,6 @@ function Draw({ sendCanvasImage }) {
const handleDragHover = (e) => {
e.preventDefault();
canvasRef.current.classList.add('opacity-25');
};
@ -98,11 +98,14 @@ function Draw({ sendCanvasImage }) {
setIsDrawing(false);
};
useEffect(() => {
canvasRef.current.width = canvasWidth.current.clientWidth;
}, [canvasWidth]);
useEffect(() => {
if (!canvasRef.current) {
return;
}
const context = canvasRef.current.getContext('2d');
if (isDrawing) {
@ -135,6 +138,7 @@ function Draw({ sendCanvasImage }) {
<div
aria-hidden
className="connect-draw__draw-area"
ref={canvasWidth}
onMouseUp={handleMouseUp}
>
<canvas
@ -146,7 +150,6 @@ function Draw({ sendCanvasImage }) {
onDragOver={handleDragHover}
onDragExit={handleDragExit}
height="600"
width="400"
/>
<div className="connect-draw__actions">
<Button