alt: PropTypes.string,
src: PropTypes.string.isRequired,
previewSrc: PropTypes.string.isRequired,
- width: PropTypes.number.isRequired,
- height: PropTypes.number.isRequired,
+ width: PropTypes.number,
+ height: PropTypes.number,
}
static defaultProps = {
alt: '',
+ width: null,
+ height: null,
};
state = {
this.setState({ loading: true, error: false });
Promise.all([
this.loadPreviewCanvas(props),
- this.loadOriginalImage(props),
- ])
+ this.hasSize() && this.loadOriginalImage(props),
+ ].filter(Boolean))
.then(() => {
this.setState({ loading: false, error: false });
this.clearPreviewCanvas();
this.removers = [];
}
+ hasSize () {
+ const { width, height } = this.props;
+ return typeof width === 'number' && typeof height === 'number';
+ }
+
setCanvasRef = c => {
this.canvas = c;
}
const className = classNames('image-loader', {
'image-loader--loading': loading,
+ 'image-loader--amorphous': !this.hasSize(),
});
return (
}
if (attachment.get('type') === 'image') {
- content = <ImageLoader previewSrc={attachment.get('preview_url')} src={url} width={attachment.getIn(['meta', 'original', 'width'])} height={attachment.getIn(['meta', 'original', 'height'])} />;
+ const width = attachment.getIn(['meta', 'original', 'width']) || null;
+ const height = attachment.getIn(['meta', 'original', 'height']) || null;
+
+ content = <ImageLoader previewSrc={attachment.get('preview_url')} src={url} width={width} height={height} />;
} else if (attachment.get('type') === 'gifv') {
content = <ExtendedVideoPlayer src={url} muted controls={false} />;
}