From b5db7fac682c3c4d7af8a9188cafce20f301a47d Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 26 Dec 2022 18:50:05 +0800 Subject: [PATCH 1/2] The poster image should not trigger a frameChange callback --- SDWebImage/Core/SDAnimatedImagePlayer.m | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/SDWebImage/Core/SDAnimatedImagePlayer.m b/SDWebImage/Core/SDAnimatedImagePlayer.m index 31cbcb67..196db572 100644 --- a/SDWebImage/Core/SDAnimatedImagePlayer.m +++ b/SDWebImage/Core/SDAnimatedImagePlayer.m @@ -145,18 +145,16 @@ if (!self.currentFrame && [self.animatedProvider isKindOfClass:[UIImage class]]) { UIImage *image = (UIImage *)self.animatedProvider; - // Use the poster image if available + // Cache the poster image if available, but should not callback to avoid caller thread issues #if SD_MAC UIImage *posterFrame = [[NSImage alloc] initWithCGImage:image.CGImage scale:image.scale orientation:kCGImagePropertyOrientationUp]; #else UIImage *posterFrame = [[UIImage alloc] initWithCGImage:image.CGImage scale:image.scale orientation:image.imageOrientation]; #endif if (posterFrame) { - self.currentFrame = posterFrame; SD_LOCK(self->_lock); - self.frameBuffer[@(self.currentFrameIndex)] = self.currentFrame; + self.frameBuffer[@(self.currentFrameIndex)] = posterFrame; SD_UNLOCK(self->_lock); - [self handleFrameChange]; } } From 717461459fe51ad7eda1f804e50d3c417c92cbfd Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 26 Dec 2022 19:05:39 +0800 Subject: [PATCH 2/2] Hack the first frame to ensure it always displayed in first screen refresh --- SDWebImage/Core/SDAnimatedImagePlayer.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SDWebImage/Core/SDAnimatedImagePlayer.m b/SDWebImage/Core/SDAnimatedImagePlayer.m index 196db572..efb6f9b8 100644 --- a/SDWebImage/Core/SDAnimatedImagePlayer.m +++ b/SDWebImage/Core/SDAnimatedImagePlayer.m @@ -152,6 +152,8 @@ UIImage *posterFrame = [[UIImage alloc] initWithCGImage:image.CGImage scale:image.scale orientation:image.imageOrientation]; #endif if (posterFrame) { + // HACK: The first frame should not check duration and immediately display + self.needsDisplayWhenImageBecomesAvailable = YES; SD_LOCK(self->_lock); self.frameBuffer[@(self.currentFrameIndex)] = posterFrame; SD_UNLOCK(self->_lock);