Merge pull request #701 from billburgess/delayplaceholder

Delay the loading of the placeholder image until after load
This commit is contained in:
Olivier Poitrey 2014-06-12 06:38:34 -07:00
commit f5bd783b5e
3 changed files with 18 additions and 5 deletions

View File

@ -68,7 +68,13 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
* the front of the queue and is loaded immediately instead of waiting for the current queue to be loaded (which
* could take a while).
*/
SDWebImageHighPriority = 1 << 8
SDWebImageHighPriority = 1 << 8,
/**
* By default, placeholder images are loaded while the image is loading. This flag will delay the loading
* of the placeholder image until after the image has finished loading.
*/
SDWebImageDelayPlaceholder = 1 << 9
};
typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType);

View File

@ -120,7 +120,7 @@
/**
* Set the imageView `image` with an `url`, placeholder and custom options.
*
* The downloand is asynchronous and cached.
* The download is asynchronous and cached.
*
* @param url The url for the image.
* @param placeholder The image to be set initially, until the image request finishes.

View File

@ -40,9 +40,11 @@ static char operationArrayKey;
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
[self cancelCurrentImageLoad];
self.image = placeholder;
if (!(options & SDWebImageDelayPlaceholder)) {
self.image = placeholder;
}
if (url) {
__weak UIImageView *wself = self;
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
@ -52,6 +54,11 @@ static char operationArrayKey;
if (image) {
wself.image = image;
[wself setNeedsLayout];
} else {
if ((options & SDWebImageDelayPlaceholder)) {
wself.image = placeholder;
[wself setNeedsLayout];
}
}
if (completedBlock && finished) {
completedBlock(image, error, cacheType);