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:
Pieter De Baets
2016-08-22 10:55:20 -07:00
committed by Facebook Github Bot 4
parent 0af640bfae
commit 84f68c338a
2 changed files with 33 additions and 3 deletions

View File

@@ -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 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
}
if (self->_onLoad) {
self->_onLoad(nil);
self->_onLoad(onLoadParamsForSource(source));
}
if (self->_onLoadEnd) {
self->_onLoadEnd(nil);