Skip to content

Commit

Permalink
Revert D5196055: [RN] Intrinsic content size for network image source…
Browse files Browse the repository at this point in the history
…s of <Image>

Differential Revision: D5196055

fbshipit-source-id: 2122029518dc6f7d1612d31b0ecfa3dd2f0dea7d
  • Loading branch information
shergin authored and facebook-github-bot committed Oct 25, 2017
1 parent efa4d3c commit e118d7a
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 37 deletions.
37 changes: 10 additions & 27 deletions Libraries/Image/RCTImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ @implementation RCTImageView

// Whether the latest change of props requires the image to be reloaded
BOOL _needsReload;

CGSize _intrinsicContentSize;
}

- (instancetype)initWithBridge:(RCTBridge *)bridge
Expand Down Expand Up @@ -112,7 +110,13 @@ - (void)dealloc

- (CGSize)intrinsicContentSize
{
return _intrinsicContentSize;
// The first `imageSource` defines intrinsic content size.
RCTImageSource *imageSource = _imageSources.firstObject;
if (!imageSource) {
return CGSizeZero;
}

return imageSource.size;
}

- (void)updateIntrinsicContentSize
Expand Down Expand Up @@ -189,12 +193,6 @@ - (void)setImageSources:(NSArray<RCTImageSource *> *)imageSources
{
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;
}
Expand Down Expand Up @@ -252,14 +250,11 @@ - (BOOL)hasMultipleSources

- (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;
}
Expand Down Expand Up @@ -306,7 +301,7 @@ - (void)reloadImage
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);
}
Expand Down Expand Up @@ -354,8 +349,6 @@ - (void)reloadImage

- (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;
Expand All @@ -372,18 +365,8 @@ - (void)imageLoaderLoadedImage:(UIImage *)loadedImage error:(NSError *)error for
}

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;
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 1 addition & 10 deletions RNTester/js/ImageExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit e118d7a

Please sign in to comment.