diff --git a/Libraries/Image/RCTImageView.m b/Libraries/Image/RCTImageView.m index 62aaa9a03..d16bebdcb 100644 --- a/Libraries/Image/RCTImageView.m +++ b/Libraries/Image/RCTImageView.m @@ -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; } diff --git a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS10@2x.png b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS10@2x.png index 97ad377b5..a272bc37e 100644 Binary files a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS10@2x.png and b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS10@2x.png differ diff --git a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS10_tvOS.png b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS10_tvOS.png index 89ce67c06..150297c88 100644 Binary files a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS10_tvOS.png and b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS10_tvOS.png differ diff --git a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS11@2x.png b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS11@2x.png index d87d03678..e19ef5117 100644 Binary files a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS11@2x.png and b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1-iOS11@2x.png differ diff --git a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1@2x.png b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1@2x.png index 13c5c5551..f367fb71a 100644 Binary files a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1@2x.png and b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1@2x.png differ diff --git a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1_tvOS.png b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1_tvOS.png index 1456852e1..a554eb08f 100644 Binary files a/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1_tvOS.png and b/RNTester/RNTesterIntegrationTests/ReferenceImages/RNTester-js-RNTesterApp.ios/testScrollViewExample_1_tvOS.png differ diff --git a/RNTester/js/ImageExample.js b/RNTester/js/ImageExample.js index 023009f93..148da2b2c 100644 --- a/RNTester/js/ImageExample.js +++ b/RNTester/js/ImageExample.js @@ -641,19 +641,10 @@ exports.examples = [ render: function() { return ( - Plain static image without explicitly set size - - Plain network image without explicitly set size - + ); }, - platform: 'ios', }, { title: 'MultipleSourcesExample',