Skip to content
Snippets Groups Projects
Commit 6713c7ad authored by Paul Kaplan's avatar Paul Kaplan
Browse files

Fix issue where dragPayload was being invalidated for sprites

Use PureComponent instead since it is a simple shouldComponentUpdate check now.
parent 9a4ef280
No related branches found
No related tags found
No related merge requests found
...@@ -80,7 +80,7 @@ const SpriteList = function (props) { ...@@ -80,7 +80,7 @@ const SpriteList = function (props) {
[styles.raised]: isRaised, [styles.raised]: isRaised,
[styles.receivedBlocks]: receivedBlocks [styles.receivedBlocks]: receivedBlocks
})} })}
dragPayload={sprite} dragPayload={sprite.id}
dragType={DragConstants.SPRITE} dragType={DragConstants.SPRITE}
id={sprite.id} id={sprite.id}
index={index} index={index}
......
...@@ -14,7 +14,7 @@ import SpriteSelectorItemComponent from '../components/sprite-selector-item/spri ...@@ -14,7 +14,7 @@ import SpriteSelectorItemComponent from '../components/sprite-selector-item/spri
const dragThreshold = 3; // Same as the block drag threshold const dragThreshold = 3; // Same as the block drag threshold
class SpriteSelectorItem extends React.Component { class SpriteSelectorItem extends React.PureComponent {
constructor (props) { constructor (props) {
super(props); super(props);
bindAll(this, [ bindAll(this, [
...@@ -33,16 +33,6 @@ class SpriteSelectorItem extends React.Component { ...@@ -33,16 +33,6 @@ class SpriteSelectorItem extends React.Component {
// Asset ID of the current decoded costume // Asset ID of the current decoded costume
this.decodedAssetId = null; this.decodedAssetId = null;
} }
shouldComponentUpdate (nextProps) {
// Ignore dragPayload due to https://github.com/LLK/scratch-gui/issues/3172.
// This function should be removed once the issue is fixed.
for (const property in nextProps) {
if (property !== 'dragPayload' && this.props[property] !== nextProps[property]) {
return true;
}
}
return false;
}
getCostumeData () { getCostumeData () {
if (this.props.costumeURL) return this.props.costumeURL; if (this.props.costumeURL) return this.props.costumeURL;
if (!this.props.asset) return null; if (!this.props.asset) return null;
...@@ -153,10 +143,7 @@ SpriteSelectorItem.propTypes = { ...@@ -153,10 +143,7 @@ SpriteSelectorItem.propTypes = {
asset: PropTypes.instanceOf(storage.Asset), asset: PropTypes.instanceOf(storage.Asset),
costumeURL: PropTypes.string, costumeURL: PropTypes.string,
dispatchSetHoveredSprite: PropTypes.func.isRequired, dispatchSetHoveredSprite: PropTypes.func.isRequired,
dragPayload: PropTypes.shape({ dragPayload: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
name: PropTypes.string,
body: PropTypes.string
}),
dragType: PropTypes.string, dragType: PropTypes.string,
dragging: PropTypes.bool, dragging: PropTypes.bool,
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
......
import jpegThumbnail from './jpeg-thumbnail'; import jpegThumbnail from './jpeg-thumbnail';
const spritePayload = (sprite, vm) => vm.exportSprite( const spritePayload = (id, vm) => {
sprite.id, const target = vm.runtime.getTargetById(id);
'base64' if (!target) return null;
).then(zippedSprite => {
const payload = {
type: 'sprite',
name: sprite.name,
mime: 'application/zip',
body: zippedSprite,
// Filled in below
thumbnail: ''
};
const costumeDataUrl = sprite.costume.asset.encodeDataURI(); return vm.exportSprite(
return jpegThumbnail(costumeDataUrl).then(thumbnail => { id,
payload.thumbnail = thumbnail.replace('data:image/jpeg;base64,', ''); 'base64'
return payload; ).then(zippedSprite => {
const payload = {
type: 'sprite',
name: target.sprite.name,
mime: 'application/zip',
body: zippedSprite,
// Filled in below
thumbnail: ''
};
const costumeDataUrl = target.sprite.costumes[target.currentCostume].asset.encodeDataURI();
return jpegThumbnail(costumeDataUrl).then(thumbnail => {
payload.thumbnail = thumbnail.replace('data:image/jpeg;base64,', '');
return payload;
});
}); });
}); };
export default spritePayload; export default spritePayload;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment