Skip to content

Commit 189c2c8

Browse files
Mo Wangfacebook-github-bot
Mo Wang
authored andcommitted
Synchronously render cached images
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
1 parent 6e03945 commit 189c2c8

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Libraries/Image/RCTImageLoader.mm

+10
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,16 @@ - (RCTImageURLLoaderRequest *)_loadImageOrDataWithURLRequest:(NSURLRequest *)req
492492
BOOL cacheResult = [loadHandler respondsToSelector:@selector(shouldCacheLoadedImages)] ?
493493
[loadHandler shouldCacheLoadedImages] : YES;
494494

495+
if (cacheResult) {
496+
UIImage *image = [[self imageCache] imageForUrl:request.URL.absoluteString
497+
size:size
498+
scale:scale
499+
resizeMode:resizeMode];
500+
if (image) {
501+
partialLoadHandler(image);
502+
}
503+
}
504+
495505
auto cancelled = std::make_shared<std::atomic<int>>(0);
496506
__block dispatch_block_t cancelLoad = nil;
497507
__block NSLock *cancelLoadLock = [NSLock new];

0 commit comments

Comments
 (0)