Skip to content

Commit 29c3049

Browse files
authored
Merge pull request #21 from SDWebImage/fix_animated_image_potential_leak
Try to stop animating when dismantle UIViewRepresentable, fix the potential leak (bug ?) for AnmatedImage
2 parents 944388f + 96e64d6 commit 29c3049

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Example/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PODS:
1111
- SDWebImage (5.2.3):
1212
- SDWebImage/Core (= 5.2.3)
1313
- SDWebImage/Core (5.2.3)
14-
- SDWebImageSwiftUI (0.3.1):
14+
- SDWebImageSwiftUI (0.3.2):
1515
- SDWebImage (~> 5.1)
1616
- SDWebImageWebPCoder (0.2.5):
1717
- libwebp (~> 1.0)
@@ -34,9 +34,9 @@ EXTERNAL SOURCES:
3434
SPEC CHECKSUMS:
3535
libwebp: 057912d6d0abfb6357d8bb05c0ea470301f5d61e
3636
SDWebImage: 46a7f73228f84ce80990c786e4372cf4db5875ce
37-
SDWebImageSwiftUI: 1b67183dd2ef0321b2ccf578775de8e47eaceb77
37+
SDWebImageSwiftUI: a8a03ef596dde2e9668a76794f6c59d194289bb0
3838
SDWebImageWebPCoder: 947093edd1349d820c40afbd9f42acb6cdecd987
3939

4040
PODFILE CHECKSUM: 3fb06a5173225e197f3a4bf2be7e5586a693257a
4141

42-
COCOAPODS: 1.8.3
42+
COCOAPODS: 1.8.4

SDWebImageSwiftUI/Classes/AnimatedImage.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ public struct AnimatedImage : PlatformViewRepresentable {
129129
public func updateNSView(_ nsView: AnimatedImageViewWrapper, context: NSViewRepresentableContext<AnimatedImage>) {
130130
updateView(nsView, context: context)
131131
}
132+
133+
public static func dismantleNSView(_ nsView: AnimatedImageViewWrapper, coordinator: ()) {
134+
dismantleView(nsView, coordinator: coordinator)
135+
}
132136
#else
133137
public func makeUIView(context: UIViewRepresentableContext<AnimatedImage>) -> AnimatedImageViewWrapper {
134138
makeView(context: context)
@@ -137,6 +141,10 @@ public struct AnimatedImage : PlatformViewRepresentable {
137141
public func updateUIView(_ uiView: AnimatedImageViewWrapper, context: UIViewRepresentableContext<AnimatedImage>) {
138142
updateView(uiView, context: context)
139143
}
144+
145+
public static func dismantleUIView(_ uiView: AnimatedImageViewWrapper, coordinator: ()) {
146+
dismantleView(uiView, coordinator: coordinator)
147+
}
140148
#endif
141149

142150
func makeView(context: PlatformViewRepresentableContext<AnimatedImage>) -> AnimatedImageViewWrapper {
@@ -175,6 +183,14 @@ public struct AnimatedImage : PlatformViewRepresentable {
175183
layoutView(view, context: context)
176184
}
177185

186+
static func dismantleView(_ view: AnimatedImageViewWrapper, coordinator: ()) {
187+
#if os(macOS)
188+
view.wrapped.animates = false
189+
#else
190+
view.wrapped.stopAnimating()
191+
#endif
192+
}
193+
178194
func layoutView(_ view: AnimatedImageViewWrapper, context: PlatformViewRepresentableContext<AnimatedImage>) {
179195
// AspectRatio
180196
if let _ = imageLayout.aspectRatio {

0 commit comments

Comments
 (0)