Merge pull request #90 from SDWebImage/bugfix_animatedImage_rare_crash

Fix the issue when dealloc AnimatedImage's native View, the window does not exist and cause internel Crash
This commit is contained in:
DreamPiggy 2020-03-29 18:44:55 +08:00 committed by GitHub
commit ca9922c044
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -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