mirror of
https://github.com/status-im/react-native.git
synced 2025-02-25 15:45:32 +00:00
Send down image source to RCTImageView onLoad callback on iOS
Summary: This allows the onLoad callback to know which image has actually loaded. This is only for iOS at the moment - implementing this for Android will require quite a bit more work. Reviewed By: majak Differential Revision: D3738759 fbshipit-source-id: b1fc2bd0dc5de90096debeab02b8f795739a4547
This commit is contained in:
parent
0af640bfae
commit
84f68c338a
@ -61,7 +61,15 @@ var NetworkImageCallbackExample = React.createClass({
|
|||||||
source={this.props.source}
|
source={this.props.source}
|
||||||
style={[styles.base, {overflow: 'visible'}]}
|
style={[styles.base, {overflow: 'visible'}]}
|
||||||
onLoadStart={() => this._loadEventFired(`✔ onLoadStart (+${new Date() - mountTime}ms)`)}
|
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={() => {
|
onLoadEnd={() => {
|
||||||
this._loadEventFired(`✔ onLoadEnd (+${new Date() - mountTime}ms)`);
|
this._loadEventFired(`✔ onLoadEnd (+${new Date() - mountTime}ms)`);
|
||||||
this.setState({startLoadPrefetched: true}, () => {
|
this.setState({startLoadPrefetched: true}, () => {
|
||||||
@ -78,7 +86,15 @@ var NetworkImageCallbackExample = React.createClass({
|
|||||||
source={this.props.prefetchedSource}
|
source={this.props.prefetchedSource}
|
||||||
style={[styles.base, {overflow: 'visible'}]}
|
style={[styles.base, {overflow: 'visible'}]}
|
||||||
onLoadStart={() => this._loadEventFired(`✔ (prefetched) onLoadStart (+${new Date() - mountTime}ms)`)}
|
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)`)}
|
onLoadEnd={() => this._loadEventFired(`✔ (prefetched) onLoadEnd (+${new Date() - mountTime}ms)`)}
|
||||||
/>
|
/>
|
||||||
: null}
|
: null}
|
||||||
|
@ -36,6 +36,20 @@ static BOOL RCTShouldReloadImageForSizeChange(CGSize currentSize, CGSize idealSi
|
|||||||
heightMultiplier > upscaleThreshold || heightMultiplier < downscaleThreshold;
|
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 ()
|
@interface RCTImageView ()
|
||||||
|
|
||||||
@property (nonatomic, strong) RCTImageSource *imageSource;
|
@property (nonatomic, strong) RCTImageSource *imageSource;
|
||||||
@ -317,7 +331,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (self->_onLoad) {
|
if (self->_onLoad) {
|
||||||
self->_onLoad(nil);
|
self->_onLoad(onLoadParamsForSource(source));
|
||||||
}
|
}
|
||||||
if (self->_onLoadEnd) {
|
if (self->_onLoadEnd) {
|
||||||
self->_onLoadEnd(nil);
|
self->_onLoadEnd(nil);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user