diff --git a/SDWebImageSwiftUI/Classes/AnimatedImage.swift b/SDWebImageSwiftUI/Classes/AnimatedImage.swift index 76e7f4e6..40dbe751 100644 --- a/SDWebImageSwiftUI/Classes/AnimatedImage.swift +++ b/SDWebImageSwiftUI/Classes/AnimatedImage.swift @@ -218,11 +218,13 @@ public struct AnimatedImage : PlatformViewRepresentable { // This is a hack because of Xcode 11.3 bug, the @Published does not trigger another `updateUIView` call // Here I have to use UIKit/AppKit API to triger the same effect (the window change implicitly cause re-render) if let hostingView = AnimatedImage.findHostingView(from: view) { - #if os(macOS) - hostingView.viewDidMoveToWindow() - #else - hostingView.didMoveToWindow() - #endif + if let _ = hostingView.window { + #if os(macOS) + hostingView.viewDidMoveToWindow() + #else + hostingView.didMoveToWindow() + #endif + } } self.imageLoading.image = image self.imageLoading.isLoading = false