Skip to content

Commit acf7d8a

Browse files
author
Duncan Hsieh
committed
reload Image when props.src is changed
1 parent 0148605 commit acf7d8a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/Image.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var RawImage = createComponent('Image', LayerMixin, {
3333
var prevProps = this._currentElement.props;
3434
var props = nextComponent.props;
3535
this.applyLayerProps(prevProps, props);
36+
this.applyImageProps(prevProps, props);
3637
this._currentElement = nextComponent;
3738
this.node.invalidateLayout();
3839
},
@@ -61,6 +62,15 @@ var Image = React.createClass({
6162
ImageCache.get(this.props.src).on('load', this.handleImageLoad);
6263
},
6364

65+
componentWillUpdate: function(nextProps, nextState) {
66+
if(nextProps.src !== this.props.src) {
67+
ImageCache.get(this.props.src).removeListener('load', this.handleImageLoad);
68+
ImageCache.get(nextProps.src).on('load', this.handleImageLoad);
69+
var loaded = ImageCache.get(nextProps.src).isLoaded();
70+
this.setState({loaded: loaded});
71+
}
72+
},
73+
6474
componentWillUnmount: function () {
6575
if (this._pendingAnimationFrame) {
6676
cancelAnimationFrame(this._pendingAnimationFrame);

0 commit comments

Comments
 (0)