Skip to content

Commit 01c68e1

Browse files
committed
Fix that AnimatedImage on macOS can not restart animation after first stop, because there are always a new set image method call
1 parent 51f3595 commit 01c68e1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

SDWebImageSwiftUI/Classes/AnimatedImage.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ public struct AnimatedImage : PlatformViewRepresentable {
211211
}
212212

213213
func updateView(_ view: AnimatedImageViewWrapper, context: PlatformViewRepresentableContext<AnimatedImage>) {
214+
// macOS SDAnimatedImageView.animates should initialize to true in advance before set image
215+
#if os(macOS)
216+
view.wrapped.animates = true
217+
#endif
218+
214219
if let image = imageModel.image {
215220
#if os(watchOS)
216221
view.wrapped.setImage(image)
@@ -228,9 +233,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
228233
}
229234

230235
#if os(macOS)
231-
if self.isAnimating != view.wrapped.animates {
232-
view.wrapped.animates = self.isAnimating
233-
}
236+
view.wrapped.animates = self.isAnimating
234237
#else
235238
if self.isAnimating != view.wrapped.isAnimating {
236239
if self.isAnimating {

0 commit comments

Comments
 (0)