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

Commit 9238d4e

Browse files
committed
Merge branch 'release/1.1.0'
2 parents 34b5b65 + bcf5daa commit 9238d4e

File tree

5 files changed

+307
-74
lines changed

5 files changed

+307
-74
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ These are the defaultProps of CanvasDraw. You can pass along any of these props
4444

4545
```javascript
4646
static defaultProps = {
47+
onChange: null
4748
loadTimeOffset: 5,
4849
lazyRadius: 30,
4950
brushRadius: 12,
@@ -56,7 +57,8 @@ These are the defaultProps of CanvasDraw. You can pass along any of these props
5657
disabled: false,
5758
imgSrc: "",
5859
saveData: null,
59-
immediateLoading: false
60+
immediateLoading: false,
61+
hideInterface: false
6062
};
6163
```
6264

demo/src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Demo extends Component {
2727
<iframe
2828
title="GitHub link"
2929
src="https://ghbtns.com/github-btn.html?user=embiem&repo=react-canvas-draw&type=star&count=true"
30-
frameborder="0"
30+
frameBorder="0"
3131
scrolling="0"
3232
width="160px"
3333
height="30px"
@@ -38,7 +38,7 @@ class Demo extends Component {
3838
default values.
3939
</p>
4040
<p>Try it out! Draw on this white canvas:</p>
41-
<CanvasDraw />
41+
<CanvasDraw onChange={() => console.log("onChange")} />
4242
<h2>Custom Brush-Color</h2>
4343
<p>
4444
Let's spice things up by using custom brush colors{" "}
@@ -69,6 +69,9 @@ class Demo extends Component {
6969
brushColor="rgba(155,12,60,0.3)"
7070
imgSrc="https://upload.wikimedia.org/wikipedia/commons/a/a1/Nepalese_Mhapuja_Mandala.jpg"
7171
/>
72+
<h2>Hide UI</h2>
73+
<p>To hide the UI elements, set the `hideInterface` prop. You can also hide the grid with the `hideGrid` prop.</p>
74+
<CanvasDraw hideInterface hideGrid />
7275
<h2>Save & Load</h2>
7376
<p>
7477
This part got me most excited. Very easy to use saving and loading of

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-canvas-draw",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "A simple yet powerful canvas-drawing component for React.",
55
"main": "lib/index.js",
66
"module": "es/index.js",
@@ -47,7 +47,9 @@
4747
"nwb": "0.21.x",
4848
"react": "^16.2.0",
4949
"react-dom": "^16.2.0",
50-
"style-loader": "^0.19.1"
50+
"style-loader": "^0.19.1",
51+
"codecov": "3.5.x",
52+
"coveralls": "3.0.x"
5153
},
5254
"author": {
5355
"name": "Martin Beierling",

src/index.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const dimensionsPropTypes = PropTypes.oneOfType([
4545

4646
export default class extends PureComponent {
4747
static propTypes = {
48+
onChange: PropTypes.func,
4849
loadTimeOffset: PropTypes.number,
4950
lazyRadius: PropTypes.number,
5051
brushRadius: PropTypes.number,
@@ -58,10 +59,12 @@ export default class extends PureComponent {
5859
disabled: PropTypes.bool,
5960
imgSrc: PropTypes.string,
6061
saveData: PropTypes.string,
61-
immediateLoading: PropTypes.bool
62+
immediateLoading: PropTypes.bool,
63+
hideInterface: PropTypes.bool
6264
};
6365

6466
static defaultProps = {
67+
onChange: null,
6568
loadTimeOffset: 5,
6669
lazyRadius: 12,
6770
brushRadius: 10,
@@ -75,7 +78,8 @@ export default class extends PureComponent {
7578
disabled: false,
7679
imgSrc: "",
7780
saveData: "",
78-
immediateLoading: false
81+
immediateLoading: false,
82+
hideInterface: false
7983
};
8084

8185
constructor(props) {
@@ -173,6 +177,7 @@ export default class extends PureComponent {
173177
const lines = this.lines.slice(0, -1);
174178
this.clear();
175179
this.simulateDrawingLines({ lines, immediate: true });
180+
this.triggerOnChange();
176181
};
177182

178183
getSaveData = () => {
@@ -234,6 +239,22 @@ export default class extends PureComponent {
234239
lines.forEach(line => {
235240
const { points, brushColor, brushRadius } = line;
236241

242+
// Draw all at once if immediate flag is set, instead of using setTimeout
243+
if (immediate) {
244+
// Draw the points
245+
this.drawPoints({
246+
points,
247+
brushColor,
248+
brushRadius
249+
});
250+
251+
// Save line with the drawn points
252+
this.points = points;
253+
this.saveLine({ brushColor, brushRadius });
254+
return;
255+
}
256+
257+
// Use timeout to draw
237258
for (let i = 1; i < points.length; i++) {
238259
curTime += timeoutGap;
239260
window.setTimeout(() => {
@@ -420,6 +441,12 @@ export default class extends PureComponent {
420441

421442
// Clear the temporary line-drawing canvas
422443
this.ctx.temp.clearRect(0, 0, width, height);
444+
445+
this.triggerOnChange();
446+
};
447+
448+
triggerOnChange = () => {
449+
this.props.onChange && this.props.onChange(this);
423450
};
424451

425452
clear = () => {
@@ -487,6 +514,8 @@ export default class extends PureComponent {
487514
};
488515

489516
drawInterface = (ctx, pointer, brush) => {
517+
if (this.props.hideInterface) return;
518+
490519
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
491520

492521
// Draw brush preview

0 commit comments

Comments
 (0)