Skip to content

Try to stop animating when dismantle UIViewRepresentable, fix the potential leak (bug ?) for AnmatedImage #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PODS:
- SDWebImage (5.2.3):
- SDWebImage/Core (= 5.2.3)
- SDWebImage/Core (5.2.3)
- SDWebImageSwiftUI (0.3.1):
- SDWebImageSwiftUI (0.3.2):
- SDWebImage (~> 5.1)
- SDWebImageWebPCoder (0.2.5):
- libwebp (~> 1.0)
Expand All @@ -34,9 +34,9 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
libwebp: 057912d6d0abfb6357d8bb05c0ea470301f5d61e
SDWebImage: 46a7f73228f84ce80990c786e4372cf4db5875ce
SDWebImageSwiftUI: 1b67183dd2ef0321b2ccf578775de8e47eaceb77
SDWebImageSwiftUI: a8a03ef596dde2e9668a76794f6c59d194289bb0
SDWebImageWebPCoder: 947093edd1349d820c40afbd9f42acb6cdecd987

PODFILE CHECKSUM: 3fb06a5173225e197f3a4bf2be7e5586a693257a

COCOAPODS: 1.8.3
COCOAPODS: 1.8.4
16 changes: 16 additions & 0 deletions SDWebImageSwiftUI/Classes/AnimatedImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public struct AnimatedImage : PlatformViewRepresentable {
public func updateNSView(_ nsView: AnimatedImageViewWrapper, context: NSViewRepresentableContext<AnimatedImage>) {
updateView(nsView, context: context)
}

public static func dismantleNSView(_ nsView: AnimatedImageViewWrapper, coordinator: ()) {
dismantleView(nsView, coordinator: coordinator)
}
#else
public func makeUIView(context: UIViewRepresentableContext<AnimatedImage>) -> AnimatedImageViewWrapper {
makeView(context: context)
Expand All @@ -137,6 +141,10 @@ public struct AnimatedImage : PlatformViewRepresentable {
public func updateUIView(_ uiView: AnimatedImageViewWrapper, context: UIViewRepresentableContext<AnimatedImage>) {
updateView(uiView, context: context)
}

public static func dismantleUIView(_ uiView: AnimatedImageViewWrapper, coordinator: ()) {
dismantleView(uiView, coordinator: coordinator)
}
#endif

func makeView(context: PlatformViewRepresentableContext<AnimatedImage>) -> AnimatedImageViewWrapper {
Expand Down Expand Up @@ -175,6 +183,14 @@ public struct AnimatedImage : PlatformViewRepresentable {
layoutView(view, context: context)
}

static func dismantleView(_ view: AnimatedImageViewWrapper, coordinator: ()) {
#if os(macOS)
view.wrapped.animates = false
#else
view.wrapped.stopAnimating()
#endif
}

func layoutView(_ view: AnimatedImageViewWrapper, context: PlatformViewRepresentableContext<AnimatedImage>) {
// AspectRatio
if let _ = imageLayout.aspectRatio {
Expand Down