From 7cc90666e822e2440c5546e860a0bc13ab4834dc Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sun, 27 Sep 2020 14:58:23 +0800 Subject: [PATCH 1/2] Fix the issue that SDAnimatedImageView will trigger an empty callback when animation stopped. This will cause some bad effect such as rendering a empty image or placeholder image (especially on iOS 14) --- SDWebImage/Core/SDAnimatedImagePlayer.m | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/SDWebImage/Core/SDAnimatedImagePlayer.m b/SDWebImage/Core/SDAnimatedImagePlayer.m index db5f123a..36ca4915 100644 --- a/SDWebImage/Core/SDAnimatedImagePlayer.m +++ b/SDWebImage/Core/SDAnimatedImagePlayer.m @@ -160,14 +160,14 @@ } } -- (void)resetCurrentFrameIndex { - self.currentFrame = nil; - self.currentFrameIndex = 0; - self.currentLoopCount = 0; - self.currentTime = 0; - self.bufferMiss = NO; - self.needsDisplayWhenImageBecomesAvailable = NO; - [self handleFrameChange]; +- (void)resetCurrentFrameStatus { + // These should not trigger KVO, user don't need to receive an `index == 0, image == nil` callback. + _currentFrame = nil; + _currentFrameIndex = 0; + _currentLoopCount = 0; + _currentTime = 0; + _bufferMiss = NO; + _needsDisplayWhenImageBecomesAvailable = NO; } - (void)clearFrameBuffer { @@ -191,7 +191,8 @@ [_fetchQueue cancelAllOperations]; // Using `_displayLink` here because when UIImageView dealloc, it may trigger `[self stopAnimating]`, we already release the display link in SDAnimatedImageView's dealloc method. [_displayLink stop]; - [self resetCurrentFrameIndex]; + // We need to reset the frame status, but not trigger any handle. This can ensure next time's playing status correct. + [self resetCurrentFrameStatus]; } - (void)pausePlaying { From 718ce147538a4f181b59f6609593af31e12c9ca7 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 28 Sep 2020 11:34:48 +0800 Subject: [PATCH 2/2] Update the test case about this stopAnimating behavior changes --- Tests/Tests/SDAnimatedImageTest.m | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/Tests/SDAnimatedImageTest.m b/Tests/Tests/SDAnimatedImageTest.m index 8d1c1f41..11936d2a 100644 --- a/Tests/Tests/SDAnimatedImageTest.m +++ b/Tests/Tests/SDAnimatedImageTest.m @@ -395,7 +395,6 @@ static const NSUInteger kTestGIFFrameCount = 5; // local TestImage.gif loop coun imageView.animates = NO; #endif expect(imageView.player.frameBuffer.count).equal(0); - expect(imageView.currentFrameIndex).equal(0); [imageView removeFromSuperview]; [expectation fulfill];