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

Commit d5af74c

Browse files
dyarfaradjAlexander K
authored andcommitted
Adds onChange (#50)
* dont-draw-interface * trigger-on-change Co-authored-by: Alexander K <rus.alexander.k@gmail.com>
1 parent 8f76ad7 commit d5af74c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

demo/src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class Demo extends Component {
3838
default values.
3939
</p>
4040
<p>Try it out! Draw on this white canvas:</p>
41-
<CanvasDraw />
41+
<CanvasDraw
42+
onChange={() => console.log('onChange') }
43+
/>
4244
<h2>Custom Brush-Color</h2>
4345
<p>
4446
Let's spice things up by using custom brush colors{" "}

src/index.js

Lines changed: 10 additions & 1 deletion
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,
@@ -62,6 +63,7 @@ export default class extends PureComponent {
6263
};
6364

6465
static defaultProps = {
66+
onChange: null,
6567
loadTimeOffset: 5,
6668
lazyRadius: 12,
6769
brushRadius: 10,
@@ -173,6 +175,7 @@ export default class extends PureComponent {
173175
const lines = this.lines.slice(0, -1);
174176
this.clear();
175177
this.simulateDrawingLines({ lines, immediate: true });
178+
this.triggerOnChange()
176179
};
177180

178181
getSaveData = () => {
@@ -436,8 +439,14 @@ export default class extends PureComponent {
436439

437440
// Clear the temporary line-drawing canvas
438441
this.ctx.temp.clearRect(0, 0, width, height);
442+
443+
this.triggerOnChange()
439444
};
440445

446+
triggerOnChange = () => {
447+
this.props.onChange && this.props.onChange(this)
448+
}
449+
441450
clear = () => {
442451
this.lines = [];
443452
this.valuesChanged = true;
@@ -460,7 +469,7 @@ export default class extends PureComponent {
460469
const pointer = this.lazy.getPointerCoordinates();
461470
const brush = this.lazy.getBrushCoordinates();
462471

463-
this.drawInterface(this.ctx.interface, pointer, brush);
472+
// this.drawInterface(this.ctx.interface, pointer, brush);
464473
this.mouseHasMoved = false;
465474
this.valuesChanged = false;
466475
}

0 commit comments

Comments
 (0)