diff --git a/Examples/UIExplorer/js/ImageExample.js b/Examples/UIExplorer/js/ImageExample.js index 618a4cc81cfb6f..0722ad76a8f8ce 100644 --- a/Examples/UIExplorer/js/ImageExample.js +++ b/Examples/UIExplorer/js/ImageExample.js @@ -61,7 +61,15 @@ var NetworkImageCallbackExample = React.createClass({ source={this.props.source} style={[styles.base, {overflow: 'visible'}]} onLoadStart={() => this._loadEventFired(`✔ onLoadStart (+${new Date() - mountTime}ms)`)} - onLoad={() => this._loadEventFired(`✔ onLoad (+${new Date() - mountTime}ms)`)} + onLoad={(event) => { + // Currently this image source feature is only available on iOS. + if (event.nativeEvent.source) { + const url = event.nativeEvent.source.url; + this._loadEventFired(`✔ onLoad (+${new Date() - mountTime}ms) for URL ${url}`); + } else { + this._loadEventFired(`✔ onLoad (+${new Date() - mountTime}ms)`); + } + }} onLoadEnd={() => { this._loadEventFired(`✔ onLoadEnd (+${new Date() - mountTime}ms)`); this.setState({startLoadPrefetched: true}, () => { @@ -78,7 +86,15 @@ var NetworkImageCallbackExample = React.createClass({ source={this.props.prefetchedSource} style={[styles.base, {overflow: 'visible'}]} onLoadStart={() => this._loadEventFired(`✔ (prefetched) onLoadStart (+${new Date() - mountTime}ms)`)} - onLoad={() => this._loadEventFired(`✔ (prefetched) onLoad (+${new Date() - mountTime}ms)`)} + onLoad={(event) => { + // Currently this image source feature is only available on iOS. + if (event.nativeEvent.source) { + const url = event.nativeEvent.source.url; + this._loadEventFired(`✔ (prefetched) onLoad (+${new Date() - mountTime}ms) for URL ${url}`); + } else { + this._loadEventFired(`✔ (prefetched) onLoad (+${new Date() - mountTime}ms)`); + } + }} onLoadEnd={() => this._loadEventFired(`✔ (prefetched) onLoadEnd (+${new Date() - mountTime}ms)`)} /> : null} diff --git a/Libraries/Image/RCTImageView.m b/Libraries/Image/RCTImageView.m index 6b915ba1809fe2..d3f65554d83798 100644 --- a/Libraries/Image/RCTImageView.m +++ b/Libraries/Image/RCTImageView.m @@ -36,6 +36,20 @@ static BOOL RCTShouldReloadImageForSizeChange(CGSize currentSize, CGSize idealSi heightMultiplier > upscaleThreshold || heightMultiplier < downscaleThreshold; } +/** + * See RCTConvert (ImageSource). We want to send down the source as a similar + * JSON parameter. + */ +static NSDictionary *onLoadParamsForSource(RCTImageSource *source) +{ + NSDictionary *dict = @{ + @"width": @(source.size.width), + @"height": @(source.size.height), + @"url": source.request.URL.absoluteString, + }; + return @{ @"source": dict }; +} + @interface RCTImageView () @property (nonatomic, strong) RCTImageSource *imageSource; @@ -317,7 +331,7 @@ - (void)imageLoaderLoadedImage:(UIImage *)loadedImage error:(NSError *)error for } if (self->_onLoad) { - self->_onLoad(nil); + self->_onLoad(onLoadParamsForSource(source)); } if (self->_onLoadEnd) { self->_onLoadEnd(nil);