diff --git a/Source/ASNetworkImageNode.mm b/Source/ASNetworkImageNode.mm index daf3a47c1..085fc063c 100644 --- a/Source/ASNetworkImageNode.mm +++ b/Source/ASNetworkImageNode.mm @@ -216,6 +216,7 @@ - (void)setURL:(NSURL *)URL resetToDefault:(BOOL)reset if (reset || hadURL) { [self _setCurrentImageQuality:(hadURL ? 0.0 : 1.0)]; [self _locked__setImage:_defaultImage]; + [self _locked_setAnimatedImage:nil]; } } diff --git a/Tests/ASNetworkImageNodeTests.mm b/Tests/ASNetworkImageNodeTests.mm index d0853c1c1..a707cd163 100644 --- a/Tests/ASNetworkImageNodeTests.mm +++ b/Tests/ASNetworkImageNodeTests.mm @@ -20,6 +20,9 @@ @interface ASTestImageDownloader : NSObject @interface ASTestImageCache : NSObject @end +@interface ASTestAnimatedImage : NSObject +@end + @implementation ASNetworkImageNodeTests { ASNetworkImageNode *node; id downloader; @@ -73,6 +76,18 @@ - (void)testThatProgressBlockIsSetAndClearedCorrectlyOnChangeURL [downloader verifyWithDelay:5]; } +- (void)testThatAnimatedImageClearedCorrectlyOnChangeURL +{ + [node layer]; + [node enterInterfaceState:ASInterfaceStateInHierarchy]; + + // Set URL while visible, should set progress block + node.animatedImage = [ASTestAnimatedImage new]; + [node setURL:[NSURL URLWithString:@"http://imageA"] resetToDefault:YES]; + + XCTAssertEqualObjects(nil, node.animatedImage); +} + - (void)testThatSettingAnImageWillStayForEnteringAndExitingPreloadState { UIImage *image = [[UIImage alloc] init]; @@ -133,3 +148,61 @@ - (void)setProgressImageBlock:(ASImageDownloaderProgressImage)progressBlock call // nop } @end + +@implementation ASTestAnimatedImage +@synthesize playbackReadyCallback; + +- (UIImage *)coverImage +{ + return [UIImage new]; +} + +- (BOOL)coverImageReady +{ + return YES; +} + +- (CFTimeInterval)totalDuration +{ + return 1; +} + +- (NSUInteger)frameInterval +{ + return 0.2; +} + +- (size_t)loopCount +{ + return 0; +} + +- (size_t)frameCount +{ + return 5; +} + +- (BOOL)playbackReady +{ + return YES; +} + +- (NSError *)error +{ + return nil; +} + +- (CGImageRef)imageAtIndex:(NSUInteger)index +{ + return [[UIImage new] CGImage]; +} + +- (CFTimeInterval)durationAtIndex:(NSUInteger)index +{ + return 0.2; +} + +- (void)clearAnimatedImageCache +{} + +@end