Skip to content

Commit c0f2531

Browse files
committed
Fix the issue when dealloc AnimatedImage's native View, the window does not exist and cause internel Crash
1 parent e8dcfc5 commit c0f2531

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

SDWebImageSwiftUI/Classes/AnimatedImage.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,13 @@ public struct AnimatedImage : PlatformViewRepresentable {
218218
// This is a hack because of Xcode 11.3 bug, the @Published does not trigger another `updateUIView` call
219219
// Here I have to use UIKit/AppKit API to triger the same effect (the window change implicitly cause re-render)
220220
if let hostingView = AnimatedImage.findHostingView(from: view) {
221-
#if os(macOS)
222-
hostingView.viewDidMoveToWindow()
223-
#else
224-
hostingView.didMoveToWindow()
225-
#endif
221+
if let _ = hostingView.window {
222+
#if os(macOS)
223+
hostingView.viewDidMoveToWindow()
224+
#else
225+
hostingView.didMoveToWindow()
226+
#endif
227+
}
226228
}
227229
self.imageLoading.image = image
228230
self.imageLoading.isLoading = false

0 commit comments

Comments
 (0)