Revert D5196055: [RN] Intrinsic content size for network image sources of <Image>
Differential Revision: D5196055 fbshipit-source-id: 2122029518dc6f7d1612d31b0ecfa3dd2f0dea7d
|
@ -81,8 +81,6 @@ static NSDictionary *onLoadParamsForSource(RCTImageSource *source)
|
|||
|
||||
// Whether the latest change of props requires the image to be reloaded
|
||||
BOOL _needsReload;
|
||||
|
||||
CGSize _intrinsicContentSize;
|
||||
}
|
||||
|
||||
- (instancetype)initWithBridge:(RCTBridge *)bridge
|
||||
|
@ -112,7 +110,13 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||
|
||||
- (CGSize)intrinsicContentSize
|
||||
{
|
||||
return _intrinsicContentSize;
|
||||
// The first `imageSource` defines intrinsic content size.
|
||||
RCTImageSource *imageSource = _imageSources.firstObject;
|
||||
if (!imageSource) {
|
||||
return CGSizeZero;
|
||||
}
|
||||
|
||||
return imageSource.size;
|
||||
}
|
||||
|
||||
- (void)updateIntrinsicContentSize
|
||||
|
@ -189,12 +193,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||
{
|
||||
if (![imageSources isEqual:_imageSources]) {
|
||||
_imageSources = [imageSources copy];
|
||||
|
||||
// If the first image source contains image size, use it to set up `_intrinsicContentSize`.
|
||||
// Otherwise we will update `_intrinsicContentSize` right after we have dowloaded image.
|
||||
// `_intrinsicContentSize` defaults to `{0, 0}` if `_imageSources` is empty.
|
||||
_intrinsicContentSize = _imageSources.firstObject.size;
|
||||
|
||||
[self updateIntrinsicContentSize];
|
||||
_needsReload = YES;
|
||||
}
|
||||
|
@ -252,14 +250,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||
|
||||
- (RCTImageSource *)imageSourceForSize:(CGSize)size
|
||||
{
|
||||
// If we have less than two sources of if we don't have intrinsic content size,
|
||||
// we have to return the first source.
|
||||
if (![self hasMultipleSources] ||
|
||||
CGSizeEqualToSize(_intrinsicContentSize, CGSizeZero)) {
|
||||
if (![self hasMultipleSources]) {
|
||||
return _imageSources.firstObject;
|
||||
}
|
||||
|
||||
// Corner case for empty size.
|
||||
// Need to wait for layout pass before deciding.
|
||||
if (CGSizeEqualToSize(size, CGSizeZero)) {
|
||||
return nil;
|
||||
}
|
||||
|
@ -306,7 +301,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||
RCTImageSource *source = [self imageSourceForSize:self.frame.size];
|
||||
_pendingImageSource = source;
|
||||
|
||||
if (source) {
|
||||
if (source && self.frame.size.width > 0 && self.frame.size.height > 0) {
|
||||
if (_onLoadStart) {
|
||||
_onLoadStart(nil);
|
||||
}
|
||||
|
@ -354,8 +349,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||
|
||||
- (void)imageLoaderLoadedImage:(UIImage *)loadedImage error:(NSError *)error forImageSource:(RCTImageSource *)source partial:(BOOL)isPartialLoad
|
||||
{
|
||||
// Can be called from any queue.
|
||||
|
||||
if (![source isEqual:_pendingImageSource]) {
|
||||
// Bail out if source has changed since we started loading
|
||||
return;
|
||||
|
@ -372,18 +365,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||
}
|
||||
|
||||
void (^setImageBlock)(UIImage *) = ^(UIImage *image) {
|
||||
RCTAssertMainQueue();
|
||||
|
||||
if (!isPartialLoad) {
|
||||
self->_imageSource = source;
|
||||
|
||||
if (CGSizeEqualToSize(self->_intrinsicContentSize, CGSizeZero) && [source isEqual:self->_imageSources.firstObject]) {
|
||||
// If we just downloaded an image from the first source and if we don't have `_intrinsicContentSize` yet,
|
||||
// use actual image size as `_intrinsicContentSize`.
|
||||
self->_intrinsicContentSize = image.size;
|
||||
[self updateIntrinsicContentSize];
|
||||
}
|
||||
|
||||
self->_pendingImageSource = nil;
|
||||
}
|
||||
|
||||
|
|
Before Width: | Height: | Size: 201 KiB After Width: | Height: | Size: 147 KiB |
Before Width: | Height: | Size: 164 KiB After Width: | Height: | Size: 96 KiB |
Before Width: | Height: | Size: 201 KiB After Width: | Height: | Size: 147 KiB |
Before Width: | Height: | Size: 201 KiB After Width: | Height: | Size: 147 KiB |
Before Width: | Height: | Size: 161 KiB After Width: | Height: | Size: 94 KiB |
|
@ -641,19 +641,10 @@ exports.examples = [
|
|||
render: function() {
|
||||
return (
|
||||
<View>
|
||||
<Text>Plain static image without explicitly set size</Text>
|
||||
<Image
|
||||
source={require('./uie_thumb_big.png')}
|
||||
style={{alignSelf: 'center'}}
|
||||
/>
|
||||
<Text>Plain network image without explicitly set size</Text>
|
||||
<Image
|
||||
source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}}
|
||||
/>
|
||||
<Image source={require('./uie_thumb_big.png')} style={{alignSelf: 'center'}} />
|
||||
</View>
|
||||
);
|
||||
},
|
||||
platform: 'ios',
|
||||
},
|
||||
{
|
||||
title: 'MultipleSourcesExample',
|
||||
|
|