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

Commit b5882c5

Browse files
committed
changes in pr
1 parent 308f55b commit b5882c5

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ These are the defaultProps of CanvasDraw. You can pass along any of these props
5858
imgSrc: "",
5959
saveData: null,
6060
immediateLoading: false,
61-
hideInterface: false,
62-
refreshBackgroundImage: false,
61+
hideInterface: false
6362
};
6463
```
6564

demo/src/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Demo extends Component {
2626
});
2727
}, 2000);
2828

29-
// let's change the background image every 15 seconds. fun!
29+
// let's change the background image every 2 seconds. fun!
3030
window.setInterval(() => {
3131
if (
3232
this.state.imgs &&
@@ -99,11 +99,9 @@ class Demo extends Component {
9999
/>
100100

101101
<h2>Refreshable Background Image</h2>
102-
<p>You can also set the `refreshBackgroundImage` prop to true is you want to enable background refreshable.</p>
103102
<p>This will refresh the background in every two seconds.</p>
104103
<CanvasDraw
105104
brushColor="rgba(155,12,60,0.3)"
106-
refreshBackgroundImage={true}
107105
imgSrc={this.state.backgroundImg}
108106
/>
109107
<h2>Hide UI</h2>

src/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ export default class extends PureComponent {
6060
imgSrc: PropTypes.string,
6161
saveData: PropTypes.string,
6262
immediateLoading: PropTypes.bool,
63-
hideInterface: PropTypes.bool,
64-
refreshBackgroundImage: PropTypes.bool,
63+
hideInterface: PropTypes.bool
6564
};
6665

6766
static defaultProps = {
@@ -80,8 +79,7 @@ export default class extends PureComponent {
8079
imgSrc: "",
8180
saveData: "",
8281
immediateLoading: false,
83-
hideInterface: false,
84-
refreshBackgroundImage: false
82+
hideInterface: false
8583
};
8684

8785
constructor(props) {
@@ -158,9 +156,8 @@ export default class extends PureComponent {
158156
this.valuesChanged = true;
159157
}
160158

161-
// Refresh the Background Canvas if refreshBackgroundImage is true
162-
if (this.props.refreshBackgroundImage) {
163-
this.drawImage();
159+
if (prevProps.imgSrc !== this.props.imgSrc) {
160+
this.drawImage();
164161
}
165162

166163
}
@@ -174,11 +171,11 @@ export default class extends PureComponent {
174171

175172
// Load the image
176173
this.image = new Image();
177-
this.image.src = this.props.imgSrc;
178174

179175
// Draw the image once loaded
180176
this.image.onload = () =>
181177
drawImage({ ctx: this.ctx.grid, img: this.image });
178+
this.image.src = this.props.imgSrc;
182179
};
183180

184181
undo = () => {
@@ -329,6 +326,7 @@ export default class extends PureComponent {
329326
this.setCanvasSize(this.canvas.grid, width, height);
330327

331328
this.drawGrid(this.ctx.grid);
329+
this.drawImage();
332330
this.loop({ once: true });
333331
}
334332
this.loadSaveData(saveData, true);

0 commit comments

Comments
 (0)