Merge pull request #701 from billburgess/delayplaceholder
Delay the loading of the placeholder image until after load
This commit is contained in:
commit
f5bd783b5e
|
@ -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
|
* the front of the queue and is loaded immediately instead of waiting for the current queue to be loaded (which
|
||||||
* could take a while).
|
* 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);
|
typedef void(^SDWebImageCompletedBlock)(UIImage *image, NSError *error, SDImageCacheType cacheType);
|
||||||
|
|
|
@ -120,7 +120,7 @@
|
||||||
/**
|
/**
|
||||||
* Set the imageView `image` with an `url`, placeholder and custom options.
|
* 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 url The url for the image.
|
||||||
* @param placeholder The image to be set initially, until the image request finishes.
|
* @param placeholder The image to be set initially, until the image request finishes.
|
||||||
|
|
|
@ -40,9 +40,11 @@ static char operationArrayKey;
|
||||||
|
|
||||||
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
|
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
|
||||||
[self cancelCurrentImageLoad];
|
[self cancelCurrentImageLoad];
|
||||||
|
|
||||||
self.image = placeholder;
|
if (!(options & SDWebImageDelayPlaceholder)) {
|
||||||
|
self.image = placeholder;
|
||||||
|
}
|
||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
__weak UIImageView *wself = self;
|
__weak UIImageView *wself = self;
|
||||||
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
|
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) {
|
if (image) {
|
||||||
wself.image = image;
|
wself.image = image;
|
||||||
[wself setNeedsLayout];
|
[wself setNeedsLayout];
|
||||||
|
} else {
|
||||||
|
if ((options & SDWebImageDelayPlaceholder)) {
|
||||||
|
wself.image = placeholder;
|
||||||
|
[wself setNeedsLayout];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (completedBlock && finished) {
|
if (completedBlock && finished) {
|
||||||
completedBlock(image, error, cacheType);
|
completedBlock(image, error, cacheType);
|
||||||
|
|
Loading…
Reference in New Issue