|
@ -8,12 +8,14 @@ export default class ImageLoader extends React.PureComponent { |
|
|
alt: PropTypes.string, |
|
|
alt: PropTypes.string, |
|
|
src: PropTypes.string.isRequired, |
|
|
src: PropTypes.string.isRequired, |
|
|
previewSrc: PropTypes.string.isRequired, |
|
|
previewSrc: PropTypes.string.isRequired, |
|
|
width: PropTypes.number.isRequired, |
|
|
|
|
|
height: PropTypes.number.isRequired, |
|
|
|
|
|
|
|
|
width: PropTypes.number, |
|
|
|
|
|
height: PropTypes.number, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static defaultProps = { |
|
|
static defaultProps = { |
|
|
alt: '', |
|
|
alt: '', |
|
|
|
|
|
width: null, |
|
|
|
|
|
height: null, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
state = { |
|
|
state = { |
|
@ -46,8 +48,8 @@ export default class ImageLoader extends React.PureComponent { |
|
|
this.setState({ loading: true, error: false }); |
|
|
this.setState({ loading: true, error: false }); |
|
|
Promise.all([ |
|
|
Promise.all([ |
|
|
this.loadPreviewCanvas(props), |
|
|
this.loadPreviewCanvas(props), |
|
|
this.loadOriginalImage(props), |
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
this.hasSize() && this.loadOriginalImage(props), |
|
|
|
|
|
].filter(Boolean)) |
|
|
.then(() => { |
|
|
.then(() => { |
|
|
this.setState({ loading: false, error: false }); |
|
|
this.setState({ loading: false, error: false }); |
|
|
this.clearPreviewCanvas(); |
|
|
this.clearPreviewCanvas(); |
|
@ -106,6 +108,11 @@ export default class ImageLoader extends React.PureComponent { |
|
|
this.removers = []; |
|
|
this.removers = []; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
hasSize () { |
|
|
|
|
|
const { width, height } = this.props; |
|
|
|
|
|
return typeof width === 'number' && typeof height === 'number'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
setCanvasRef = c => { |
|
|
setCanvasRef = c => { |
|
|
this.canvas = c; |
|
|
this.canvas = c; |
|
|
} |
|
|
} |
|
@ -116,6 +123,7 @@ export default class ImageLoader extends React.PureComponent { |
|
|
|
|
|
|
|
|
const className = classNames('image-loader', { |
|
|
const className = classNames('image-loader', { |
|
|
'image-loader--loading': loading, |
|
|
'image-loader--loading': loading, |
|
|
|
|
|
'image-loader--amorphous': !this.hasSize(), |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|