diff --git a/Libraries/Image/RCTImageLoader.mm b/Libraries/Image/RCTImageLoader.mm index 278256f16889fe..228e9e6fe80c28 100644 --- a/Libraries/Image/RCTImageLoader.mm +++ b/Libraries/Image/RCTImageLoader.mm @@ -801,15 +801,15 @@ - (void)trackURLImageVisibilityForRequest:(RCTImageURLLoaderRequest *)loaderRequ } } -- (void)trackURLImageRequestDidCancel:(RCTImageURLLoaderRequest *)loaderRequest +- (void)trackURLImageRequestDidDestroy:(RCTImageURLLoaderRequest *)loaderRequest { if (!loaderRequest) { return; } id loadHandler = [self imageURLLoaderForURL:loaderRequest.imageURL]; - if ([loadHandler respondsToSelector:@selector(trackURLImageRequestDidCancel:)]) { - [(id)loadHandler trackURLImageRequestDidCancel:loaderRequest]; + if ([loadHandler respondsToSelector:@selector(trackURLImageRequestDidDestroy:)]) { + [(id)loadHandler trackURLImageRequestDidDestroy:loaderRequest]; } } diff --git a/Libraries/Image/RCTImageLoaderWithAttributionProtocol.h b/Libraries/Image/RCTImageLoaderWithAttributionProtocol.h index c6d1413b3816fc..19bf8c4831bb1e 100644 --- a/Libraries/Image/RCTImageLoaderWithAttributionProtocol.h +++ b/Libraries/Image/RCTImageLoaderWithAttributionProtocol.h @@ -47,7 +47,7 @@ RCT_EXTERN void RCTEnableImageLoadingPerfInstrumentation(BOOL enabled); /** * Image instrumentation - notify that the request was cancelled. */ -- (void)trackURLImageRequestDidCancel:(RCTImageURLLoaderRequest *)loaderRequest; +- (void)trackURLImageRequestDidDestroy:(RCTImageURLLoaderRequest *)loaderRequest; /** * Image instrumentation - notify that the native image view was destroyed. diff --git a/Libraries/Image/RCTImageURLLoaderWithAttribution.h b/Libraries/Image/RCTImageURLLoaderWithAttribution.h index d976b43d887e0b..d7632746346a44 100644 --- a/Libraries/Image/RCTImageURLLoaderWithAttribution.h +++ b/Libraries/Image/RCTImageURLLoaderWithAttribution.h @@ -66,9 +66,9 @@ struct ImageURLLoaderAttribution { - (void)trackURLImageVisibilityForRequest:(RCTImageURLLoaderRequest *)loaderRequest imageView:(UIView *)imageView; /** - * Image instrumentation - notify that the request was cancelled. + * Image instrumentation - notify that the request was destroyed. */ -- (void)trackURLImageRequestDidCancel:(RCTImageURLLoaderRequest *)loaderRequest; +- (void)trackURLImageRequestDidDestroy:(RCTImageURLLoaderRequest *)loaderRequest; /** * Image instrumentation - notify that the native image view was destroyed. diff --git a/Libraries/Image/RCTImageView.mm b/Libraries/Image/RCTImageView.mm index a8b78c52d90f4a..11a0d7838e915d 100644 --- a/Libraries/Image/RCTImageView.mm +++ b/Libraries/Image/RCTImageView.mm @@ -80,7 +80,7 @@ @implementation RCTImageView BOOL _needsReload; RCTUIImageViewAnimated *_imageView; - + RCTImageURLLoaderRequest *_loaderRequest; } @@ -219,23 +219,23 @@ - (void)setResizeMode:(RCTResizeMode)resizeMode - (void)cancelImageLoad { [_loaderRequest cancel]; - [_imageLoader trackURLImageRequestDidCancel:_loaderRequest]; - - _loaderRequest = nil; _pendingImageSource = nil; } -- (void)clearImage +- (void)cancelAndClearImageLoad { [self cancelImageLoad]; - self.image = nil; - _imageSource = nil; + + [_imageLoader trackURLImageRequestDidDestroy:_loaderRequest]; + _loaderRequest = nil; } - (void)clearImageIfDetached { if (!self.window) { - [self clearImage]; + [self cancelAndClearImageLoad]; + self.image = nil; + _imageSource = nil; } } @@ -291,7 +291,7 @@ - (BOOL)shouldChangeImageSource - (void)reloadImage { - [self cancelImageLoad]; + [self cancelAndClearImageLoad]; _needsReload = NO; RCTImageSource *source = [self imageSourceForSize:self.frame.size]; @@ -347,7 +347,7 @@ - (void)reloadImage completionBlock:completionHandler]; _loaderRequest = loaderRequest; } else { - [self clearImage]; + [self cancelAndClearImageLoad]; } } @@ -467,6 +467,7 @@ - (void)didMoveToWindow // prioritise image requests that are actually on-screen, this removes // requests that have gotten "stuck" from the queue, unblocking other images // from loading. + // Do not clear _loaderRequest because this component can be visible again without changing image source [self cancelImageLoad]; } else if ([self shouldChangeImageSource]) { [self reloadImage];