Merge pull request #3030 from PhilipDukhov/master

SDAnimatedImagePlayer seek returning nil image fix
This commit is contained in:
DreamPiggy 2020-06-11 17:51:40 +08:00 committed by GitHub
commit 121a18568d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -209,6 +209,7 @@
}
self.currentFrameIndex = index;
self.currentLoopCount = loopCount;
self.currentFrame = [self.animatedProvider animatedImageFrameAtIndex:index];
[self handleFrameChange];
}

View File

@ -523,6 +523,39 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun
[self waitForExpectationsWithCommonTimeout];
}
- (void)test29AnimatedImageSeekFrame {
XCTestExpectation *expectation = [self expectationWithDescription:@"test SDAnimatedImageView stopAnimating normal behavior"];
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
#if SD_UIKIT
[self.window addSubview:imageView];
#else
[self.window.contentView addSubview:imageView];
#endif
// seeking through local image should return non-null images
SDAnimatedImage *image = [SDAnimatedImage imageWithData:[self testAPNGPData]];
imageView.autoPlayAnimatedImage = NO;
imageView.image = image;
__weak SDAnimatedImagePlayer *player = imageView.player;
__block NSUInteger i = 0;
[player setAnimationFrameHandler:^(NSUInteger index, UIImage * _Nonnull frame) {
expect(index).equal(i);
expect(frame).notTo.beNil();
i++;
if (i < player.totalFrameCount) {
[player seekToFrameAtIndex:i loopCount:0];
} else {
[expectation fulfill];
}
}];
[player seekToFrameAtIndex:i loopCount:0];
[self waitForExpectationsWithCommonTimeout];
}
#pragma mark - Helper
- (UIWindow *)window {
if (!_window) {