Skip to content

Commit a5c8082

Browse files
committed
Fix the issue that WebImage will stop download after first progressive loading image loaded
1 parent b5d775f commit a5c8082

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Example/SDWebImageSwiftUIDemo/ContentView.swift

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct ContentView: View {
2929
"https://isparta.github.io/compare-webp/image/gif_webp/webp/2.webp",
3030
"https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic",
3131
"https://nokiatech.github.io/heif/content/image_sequences/starfield_animation.heic",
32+
"https://www.sample-videos.com/img/Sample-png-image-1mb.png",
3233
"https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png",
3334
"http://via.placeholder.com/200x200.jpg"]
3435
@State var animated: Bool = true // You can change between WebImage/AnimatedImage

SDWebImageSwiftUI/Classes/ImageManager.swift

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import SDWebImage
1212
class ImageManager : ObservableObject {
1313
@Published var image: PlatformImage?
1414
@Published var isLoading: Bool = false
15+
@Published var isIncremental: Bool = false
1516
@Published var progress: CGFloat = 0
1617

1718
var manager = SDWebImageManager.shared
@@ -56,6 +57,7 @@ class ImageManager : ObservableObject {
5657
if let image = image {
5758
self.image = image
5859
}
60+
self.isIncremental = !finished
5961
if finished {
6062
self.isLoading = false
6163
self.progress = 1

SDWebImageSwiftUI/Classes/WebImage.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import SwiftUI
1010
import SDWebImage
1111

1212
public struct WebImage : View {
13-
static var emptyImage = Image(platformImage: PlatformImage())
13+
static var emptyImage = PlatformImage()
1414

1515
var url: URL?
1616
var placeholder: Image?
@@ -46,7 +46,7 @@ public struct WebImage : View {
4646
let view = image
4747
return AnyView(view)
4848
} else {
49-
var image = placeholder ?? WebImage.emptyImage
49+
var image = placeholder ?? Image(platformImage: WebImage.emptyImage)
5050
image = configurations.reduce(image) { (previous, configuration) in
5151
configuration(previous)
5252
}
@@ -57,7 +57,10 @@ public struct WebImage : View {
5757
}
5858
}
5959
.onDisappear {
60-
self.imageManager.cancel()
60+
// When using prorgessive loading, the previous partial image will cause onDisappear. Filter this case
61+
if self.imageManager.isLoading && !self.imageManager.isIncremental {
62+
self.imageManager.cancel()
63+
}
6164
}
6265
return AnyView(view)
6366
}

0 commit comments

Comments
 (0)