Skip to content

Commit

Permalink
Remove redundant queue switch from RCTLocalAssetImageLoader
Browse files Browse the repository at this point in the history
Summary:
Switching queues in `RCTLocalAssetImageLoader` is unnecessary. We dispatch to main queue before assigning the image to `UIImageView`.

Changelog: Remove redundant queue switch from RCTLocalAssetImageLoader

Reviewed By: PeteTheHeat

Differential Revision: D20347223

fbshipit-source-id: ff6215838f0462356d4a516e6ec31c82a742881a
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Mar 11, 2020
1 parent f3a53fd commit 3198009
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions Libraries/Image/RCTLocalAssetImageLoader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,19 @@ - (RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
partialLoadHandler:(RCTImageLoaderPartialLoadBlock)partialLoadHandler
completionHandler:(RCTImageLoaderCompletionBlock)completionHandler
{
__block auto cancelled = std::make_shared<std::atomic<bool>>(false);
RCTExecuteOnMainQueue(^{
if (cancelled->load()) {
return;
UIImage *image = RCTImageFromLocalAssetURL(imageURL);
if (image) {
if (progressHandler) {
progressHandler(1, 1);
}

UIImage *image = RCTImageFromLocalAssetURL(imageURL);
if (image) {
if (progressHandler) {
progressHandler(1, 1);
}
completionHandler(nil, image);
} else {
NSString *message = [NSString stringWithFormat:@"Could not find image %@", imageURL];
RCTLogWarn(@"%@", message);
completionHandler(RCTErrorWithMessage(message), nil);
}
});

return ^{
cancelled->store(true);
};
completionHandler(nil, image);
} else {
NSString *message = [NSString stringWithFormat:@"Could not find image %@", imageURL];
RCTLogWarn(@"%@", message);
completionHandler(RCTErrorWithMessage(message), nil);
}

return nil;
}

@end
Expand Down

0 comments on commit 3198009

Please sign in to comment.