Skip to content

Commit

Permalink
Synchronously render cached images
Browse files Browse the repository at this point in the history
Summary:
## Problem
Previously the RN Image render the cached images asynchronously (line 555 and 594 prior to the change), which caused the images to render at least a frame later than the adjacent components.

## Change
In this change, we call partialLoadHandler with the cached image synchronously on the main thread.

Changelog: [iOS][Changed] - Synchronously render cached images

Reviewed By: p-sun

Differential Revision: D34487673

fbshipit-source-id: 0600c2fa5f7a1eca71b8582bbe968694cf211468
  • Loading branch information
Mo Wang authored and facebook-github-bot committed Feb 26, 2022
1 parent 6e03945 commit 189c2c8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Libraries/Image/RCTImageLoader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,16 @@ - (RCTImageURLLoaderRequest *)_loadImageOrDataWithURLRequest:(NSURLRequest *)req
BOOL cacheResult = [loadHandler respondsToSelector:@selector(shouldCacheLoadedImages)] ?
[loadHandler shouldCacheLoadedImages] : YES;

if (cacheResult) {
UIImage *image = [[self imageCache] imageForUrl:request.URL.absoluteString
size:size
scale:scale
resizeMode:resizeMode];
if (image) {
partialLoadHandler(image);
}
}

auto cancelled = std::make_shared<std::atomic<int>>(0);
__block dispatch_block_t cancelLoad = nil;
__block NSLock *cancelLoadLock = [NSLock new];
Expand Down

0 comments on commit 189c2c8

Please sign in to comment.