mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-23 05:52:42 -05:00
Add SVG id prop to track costume changes
Since the editor will receive an update every time the svg is updated, only re-render if the actual svg id changes.
This commit is contained in:
parent
303b4caced
commit
138718008c
4 changed files with 8 additions and 1 deletions
|
@ -169,6 +169,7 @@ class PaintEditorComponent extends React.Component {
|
||||||
rotationCenterX={this.props.rotationCenterX}
|
rotationCenterX={this.props.rotationCenterX}
|
||||||
rotationCenterY={this.props.rotationCenterY}
|
rotationCenterY={this.props.rotationCenterY}
|
||||||
svg={this.props.svg}
|
svg={this.props.svg}
|
||||||
|
svgId={this.props.svgId}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -186,7 +187,8 @@ PaintEditorComponent.propTypes = {
|
||||||
onUpdateSvg: PropTypes.func.isRequired,
|
onUpdateSvg: PropTypes.func.isRequired,
|
||||||
rotationCenterX: PropTypes.number,
|
rotationCenterX: PropTypes.number,
|
||||||
rotationCenterY: PropTypes.number,
|
rotationCenterY: PropTypes.number,
|
||||||
svg: PropTypes.string
|
svg: PropTypes.string,
|
||||||
|
svgId: PropTypes.string
|
||||||
};
|
};
|
||||||
|
|
||||||
export default injectIntl(PaintEditorComponent);
|
export default injectIntl(PaintEditorComponent);
|
||||||
|
|
|
@ -58,6 +58,7 @@ class PaintEditor extends React.Component {
|
||||||
rotationCenterX={this.props.rotationCenterX}
|
rotationCenterX={this.props.rotationCenterX}
|
||||||
rotationCenterY={this.props.rotationCenterY}
|
rotationCenterY={this.props.rotationCenterY}
|
||||||
svg={this.props.svg}
|
svg={this.props.svg}
|
||||||
|
svgId={this.props.svgId}
|
||||||
onRedo={this.handleRedo}
|
onRedo={this.handleRedo}
|
||||||
onUndo={this.handleUndo}
|
onUndo={this.handleUndo}
|
||||||
onUpdateName={this.props.onUpdateName}
|
onUpdateName={this.props.onUpdateName}
|
||||||
|
@ -77,6 +78,7 @@ PaintEditor.propTypes = {
|
||||||
rotationCenterX: PropTypes.number,
|
rotationCenterX: PropTypes.number,
|
||||||
rotationCenterY: PropTypes.number,
|
rotationCenterY: PropTypes.number,
|
||||||
svg: PropTypes.string,
|
svg: PropTypes.string,
|
||||||
|
svgId: PropTypes.string,
|
||||||
undoSnapshot: PropTypes.func.isRequired,
|
undoSnapshot: PropTypes.func.isRequired,
|
||||||
undoState: PropTypes.shape({
|
undoState: PropTypes.shape({
|
||||||
stack: PropTypes.arrayOf(PropTypes.object).isRequired,
|
stack: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||||
|
|
|
@ -29,6 +29,7 @@ class PaperCanvas extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
componentWillReceiveProps (newProps) {
|
componentWillReceiveProps (newProps) {
|
||||||
|
if (this.props.svgId === newProps.svgId) return;
|
||||||
for (const layer of paper.project.layers) {
|
for (const layer of paper.project.layers) {
|
||||||
layer.removeChildren();
|
layer.removeChildren();
|
||||||
}
|
}
|
||||||
|
@ -108,6 +109,7 @@ PaperCanvas.propTypes = {
|
||||||
rotationCenterX: PropTypes.number,
|
rotationCenterX: PropTypes.number,
|
||||||
rotationCenterY: PropTypes.number,
|
rotationCenterY: PropTypes.number,
|
||||||
svg: PropTypes.string,
|
svg: PropTypes.string,
|
||||||
|
svgId: PropTypes.string,
|
||||||
undoSnapshot: PropTypes.func.isRequired
|
undoSnapshot: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = dispatch => ({
|
||||||
|
|
|
@ -49,6 +49,7 @@ class Playground extends React.Component {
|
||||||
return (
|
return (
|
||||||
<PaintEditor
|
<PaintEditor
|
||||||
{...this.state}
|
{...this.state}
|
||||||
|
svgId="meow"
|
||||||
onUpdateName={this.handleUpdateName}
|
onUpdateName={this.handleUpdateName}
|
||||||
onUpdateSvg={this.handleUpdateSvg}
|
onUpdateSvg={this.handleUpdateSvg}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in a new issue