Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-[ASNetworkImageNode setURL:resetToDefault:] forget to reset animatedImage #1861

Merged
merged 2 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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