Skip to content
This repository was archived by the owner on Aug 1, 2022. It is now read-only.

Commit 54897cc

Browse files
committed
Merge branch 'release/1.1.1'
2 parents 9238d4e + 3f08282 commit 54897cc

File tree

3 files changed

+64
-34
lines changed

3 files changed

+64
-34
lines changed

CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
9+
10+
## [1.1.1] - 2020-04-27
11+
### Added
12+
- Started this CHANGELOG.md file to keep track of any changes per version
13+
14+
### Fixed
15+
- Fix touch draw issue. (https://github.com/embiem/react-canvas-draw/issues/29)
16+
- Fix "Can't draw dots" issue. (https://github.com/embiem/react-canvas-draw/issues/42)
17+
- Fix image not shown due to cache. (https://github.com/embiem/react-canvas-draw/issues/59)
18+
- Fix image issues on canvas resize. (https://github.com/embiem/react-canvas-draw/issues/66)
19+
- Fix SecurityError on save. (https://github.com/embiem/react-canvas-draw/issues/70)
20+
21+
### Changed
22+
- Unified touch & mouse events to streamline core draw logic (handleDrawStart, handleDrawMove & handleDrawEnd)
23+
24+
## [1.1.0] - 2019-12-29
25+
### Added
26+
- onChange prop #50 (https://github.com/embiem/react-canvas-draw/pull/50)
27+
28+
### Fixed
29+
- Fix "Immediate flag should be really immediate" issue #30 (https://github.com/embiem/react-canvas-draw/issues/30)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-canvas-draw",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "A simple yet powerful canvas-drawing component for React.",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/index.js

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,14 @@ export default class extends PureComponent {
166166

167167
// Load the image
168168
this.image = new Image();
169-
this.image.src = this.props.imgSrc;
169+
170+
// Prevent SecurityError "Tainted canvases may not be exported." #70
171+
this.image.crossOrigin = "anonymous";
170172

171173
// Draw the image once loaded
172174
this.image.onload = () =>
173175
drawImage({ ctx: this.ctx.grid, img: this.image });
176+
this.image.src = this.props.imgSrc;
174177
};
175178

176179
undo = () => {
@@ -275,42 +278,39 @@ export default class extends PureComponent {
275278
});
276279
};
277280

278-
handleTouchStart = e => {
279-
const { x, y } = this.getPointerPos(e);
280-
this.lazy.update({ x, y }, { both: true });
281-
this.handleMouseDown(e);
281+
handleDrawStart = e => {
282+
e.preventDefault();
282283

283-
this.mouseHasMoved = true;
284-
};
284+
// Start drawing
285+
this.isPressing = true;
285286

286-
handleTouchMove = e => {
287-
e.preventDefault();
288287
const { x, y } = this.getPointerPos(e);
289-
this.handlePointerMove(x, y);
290-
};
291288

292-
handleTouchEnd = e => {
293-
this.handleMouseUp(e);
294-
const brush = this.lazy.getBrushCoordinates();
295-
this.lazy.update({ x: brush.x, y: brush.y }, { both: true });
296-
this.mouseHasMoved = true;
289+
if (e.touches && e.touches.length > 0) {
290+
// on touch, set catenary position to touch pos
291+
this.lazy.update({ x, y }, { both: true });
292+
}
293+
294+
// Ensure the initial down position gets added to our line
295+
this.handlePointerMove(x, y);
297296
};
298297

299-
handleMouseDown = e => {
298+
handleDrawMove = e => {
300299
e.preventDefault();
301-
this.isPressing = true;
302-
};
303300

304-
handleMouseMove = e => {
305301
const { x, y } = this.getPointerPos(e);
306302
this.handlePointerMove(x, y);
307303
};
308304

309-
handleMouseUp = e => {
305+
handleDrawEnd = e => {
310306
e.preventDefault();
307+
308+
// Draw to this end pos
309+
this.handleDrawMove(e);
310+
311+
// Stop drawing & save the drawn line
311312
this.isDrawing = false;
312313
this.isPressing = false;
313-
314314
this.saveLine();
315315
};
316316

@@ -324,6 +324,7 @@ export default class extends PureComponent {
324324
this.setCanvasSize(this.canvas.grid, width, height);
325325

326326
this.drawGrid(this.ctx.grid);
327+
this.drawImage();
327328
this.loop({ once: true });
328329
}
329330
this.loadSaveData(saveData, true);
@@ -359,19 +360,19 @@ export default class extends PureComponent {
359360
handlePointerMove = (x, y) => {
360361
if (this.props.disabled) return;
361362

362-
const hasChanged = this.lazy.update({ x, y });
363+
this.lazy.update({ x, y });
363364
const isDisabled = !this.lazy.isEnabled();
364365

365366
if (
366-
(this.isPressing && hasChanged && !this.isDrawing) ||
367+
(this.isPressing && !this.isDrawing) ||
367368
(isDisabled && this.isPressing)
368369
) {
369370
// Start drawing and add point
370371
this.isDrawing = true;
371372
this.points.push(this.lazy.brush.toObject());
372373
}
373374

374-
if (this.isDrawing && (this.lazy.brushHasMoved() || isDisabled)) {
375+
if (this.isDrawing) {
375376
// Add new point
376377
this.points.push(this.lazy.brush.toObject());
377378

@@ -583,14 +584,14 @@ export default class extends PureComponent {
583584
}
584585
}}
585586
style={{ ...canvasStyle, zIndex }}
586-
onMouseDown={isInterface ? this.handleMouseDown : undefined}
587-
onMouseMove={isInterface ? this.handleMouseMove : undefined}
588-
onMouseUp={isInterface ? this.handleMouseUp : undefined}
589-
onMouseOut={isInterface ? this.handleMouseUp : undefined}
590-
onTouchStart={isInterface ? this.handleTouchStart : undefined}
591-
onTouchMove={isInterface ? this.handleTouchMove : undefined}
592-
onTouchEnd={isInterface ? this.handleTouchEnd : undefined}
593-
onTouchCancel={isInterface ? this.handleTouchEnd : undefined}
587+
onMouseDown={isInterface ? this.handleDrawStart : undefined}
588+
onMouseMove={isInterface ? this.handleDrawMove : undefined}
589+
onMouseUp={isInterface ? this.handleDrawEnd : undefined}
590+
onMouseOut={isInterface ? this.handleDrawEnd : undefined}
591+
onTouchStart={isInterface ? this.handleDrawStart : undefined}
592+
onTouchMove={isInterface ? this.handleDrawMove : undefined}
593+
onTouchEnd={isInterface ? this.handleDrawEnd : undefined}
594+
onTouchCancel={isInterface ? this.handleDrawEnd : undefined}
594595
/>
595596
);
596597
})}

0 commit comments

Comments
 (0)