Revert "Let ASMultiplexImageNode skip failed image identifiers"

This commit is contained in:
Nadine Salter
2015-02-09 16:35:38 -08:00
parent 8848c0db92
commit 3b8f275a2a
2 changed files with 8 additions and 23 deletions

View File

@@ -68,11 +68,6 @@ typedef NS_ENUM(NSUInteger, ASMultiplexImageNodeErrorCode) {
*/ */
@property (nonatomic, readwrite, assign) BOOL downloadsIntermediateImages; @property (nonatomic, readwrite, assign) BOOL downloadsIntermediateImages;
/**
* @abstract Indicates that the receiver should stop loading if it encounters an error while loading an intermediate image identifier. Defaults to NO.
*/
@property (nonatomic, readwrite, assign) BOOL haltsLoadingOnError;
/** /**
* @abstract An array of identifiers representing various versions of an image for ASMultiplexImageNode to display. * @abstract An array of identifiers representing various versions of an image for ASMultiplexImageNode to display.
* *

View File

@@ -62,13 +62,11 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
// Image flags. // Image flags.
BOOL _downloadsIntermediateImages; // Defaults to NO. BOOL _downloadsIntermediateImages; // Defaults to NO.
BOOL _haltsLoadingOnError; // Defaults to NO.
OSSpinLock _imageIdentifiersLock; OSSpinLock _imageIdentifiersLock;
NSArray *_imageIdentifiers; NSArray *_imageIdentifiers;
id _loadedImageIdentifier; id _loadedImageIdentifier;
id _loadingImageIdentifier; id _loadingImageIdentifier;
id _displayedImageIdentifier; id _displayedImageIdentifier;
id _failedImageIdentifier; // Reset to nil whenever an image is successfully loaded
// Networking. // Networking.
id _downloadIdentifier; id _downloadIdentifier;
@@ -355,11 +353,9 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
{ {
OSSpinLockLock(&_imageIdentifiersLock); OSSpinLockLock(&_imageIdentifiersLock);
id currentImageIdentifier = _failedImageIdentifier != nil ? _failedImageIdentifier : _loadedImageIdentifier;
// If we've already loaded the best identifier, we've got nothing else to do. // If we've already loaded the best identifier, we've got nothing else to do.
id bestImageIdentifier = ([_imageIdentifiers count] > 0) ? _imageIdentifiers[0] : nil; id bestImageIdentifier = ([_imageIdentifiers count] > 0) ? _imageIdentifiers[0] : nil;
if (!bestImageIdentifier || [currentImageIdentifier isEqual:bestImageIdentifier]) { if (!bestImageIdentifier || [_loadedImageIdentifier isEqual:bestImageIdentifier]) {
OSSpinLockUnlock(&_imageIdentifiersLock); OSSpinLockUnlock(&_imageIdentifiersLock);
return nil; return nil;
} }
@@ -372,15 +368,15 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
} }
// Otherwise, load progressively. // Otherwise, load progressively.
else { else {
NSUInteger currentIndex = [_imageIdentifiers indexOfObject:currentImageIdentifier]; NSUInteger loadedIndex = [_imageIdentifiers indexOfObject:_loadedImageIdentifier];
// If nothing has loaded yet, load the worst identifier. // If nothing has loaded yet, load the worst identifier.
if (currentIndex == NSNotFound) { if (loadedIndex == NSNotFound) {
nextImageIdentifierToDownload = [_imageIdentifiers lastObject]; nextImageIdentifierToDownload = [_imageIdentifiers lastObject];
} }
// Otherwise, load the next best identifier (if there is one) // Otherwise, load the next best identifier (if there is one)
else if (currentIndex > 0) { else if (loadedIndex > 0) {
nextImageIdentifierToDownload = _imageIdentifiers[currentIndex - 1]; nextImageIdentifierToDownload = _imageIdentifiers[loadedIndex - 1];
} }
} }
@@ -592,16 +588,10 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
#pragma mark - #pragma mark -
- (void)_finishedLoadingImage:(UIImage *)image forIdentifier:(id)imageIdentifier error:(NSError *)error - (void)_finishedLoadingImage:(UIImage *)image forIdentifier:(id)imageIdentifier error:(NSError *)error
{ {
// If we failed to load and _haltsLoadingOnError is YES, we stop the loading process. // If we failed to load, we stop the loading process.
// Note that if we bailed before we began downloading because the best identifier changed, we don't bail, but rather just begin loading the best image identifier. // Note that if we bailed before we began downloading because the best identifier changed, we don't bail, but rather just begin loading the best image identifier.
if (error && error.code != ASMultiplexImageNodeErrorCodeBestImageIdentifierChanged) { if (error && error.code != ASMultiplexImageNodeErrorCodeBestImageIdentifierChanged)
if (_haltsLoadingOnError) {
return; return;
}
_failedImageIdentifier = imageIdentifier;
} else {
_failedImageIdentifier = nil;
}
OSSpinLockLock(&_imageIdentifiersLock); OSSpinLockLock(&_imageIdentifiersLock);
NSUInteger imageIdentifierCount = [_imageIdentifiers count]; NSUInteger imageIdentifierCount = [_imageIdentifiers count];