Skip to content

Commit

Permalink
fix: image cache did not take into account request cache policy (#34556)
Browse files Browse the repository at this point in the history
Summary:
Image Component cache = 'reload' prop not worked correct because inner Image cache did not take into account request cache (cache property convert in RCTConvert into request.cachePolicy).

Fixes #9195

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[IOS] [Fixed] - Image Component will not update correctly when passing in new url

Pull Request resolved: #34556

Test Plan: Reproduce code: https://snack.expo.dev/rundbom/image-should-update

Reviewed By: cipolleschi

Differential Revision: D39206324

Pulled By: jacdebug

fbshipit-source-id: 2293382279e92f3b2bfcd36b54af47d1813c5cdf
  • Loading branch information
matpaul authored and facebook-github-bot committed Sep 5, 2022
1 parent 1dd74db commit 5c211f2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Libraries/Image/RCTImageLoader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ - (RCTImageURLLoaderRequest *)_loadImageOrDataWithURLRequest:(NSURLRequest *)req
BOOL cacheResult = [loadHandler respondsToSelector:@selector(shouldCacheLoadedImages)] ?
[loadHandler shouldCacheLoadedImages] : YES;

if (request.cachePolicy == NSURLRequestReloadIgnoringLocalCacheData) {
cacheResult = NO;
}

if (cacheResult && partialLoadHandler) {
UIImage *image = [[self imageCache] imageForUrl:request.URL.absoluteString
size:size
Expand Down

0 comments on commit 5c211f2

Please sign in to comment.