Skip to content

Commit

Permalink
-[ASNetworkImageNode setURL:resetToDefault:] forget to reset animated…
Browse files Browse the repository at this point in the history
…Image (#1861)

* Fix -[ASNetworkImageNode setURL:resetToDefault:] forget to reset animatedImage

* add ASNetworkImageNodeTest for reset with animatedImage
  • Loading branch information
IvanChan authored and garrettmoon committed Jun 25, 2020
1 parent 138c13a commit 390a7b2
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions Source/ASNetworkImageNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

Expand Down
73 changes: 73 additions & 0 deletions Tests/ASNetworkImageNodeTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ @interface ASTestImageDownloader : NSObject <ASImageDownloaderProtocol>
@interface ASTestImageCache : NSObject <ASImageCacheProtocol>
@end

@interface ASTestAnimatedImage : NSObject <ASAnimatedImageProtocol>
@end

@implementation ASNetworkImageNodeTests {
ASNetworkImageNode *node;
id downloader;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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

0 comments on commit 390a7b2

Please sign in to comment.