Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix the issue that WebImage will stop download after first progressiv…
…e loading image loaded
  • Loading branch information
dreampiggy committed Nov 1, 2019
commit a5c8082b796ec22ee824e6a29c303c2c4fd1f92c
1 change: 1 addition & 0 deletions Example/SDWebImageSwiftUIDemo/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct ContentView: View {
"https://isparta.github.io/compare-webp/image/gif_webp/webp/2.webp",
"https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic",
"https://nokiatech.github.io/heif/content/image_sequences/starfield_animation.heic",
"https://www.sample-videos.com/img/Sample-png-image-1mb.png",
"https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png",
"http://via.placeholder.com/200x200.jpg"]
@State var animated: Bool = true // You can change between WebImage/AnimatedImage
Expand Down
2 changes: 2 additions & 0 deletions SDWebImageSwiftUI/Classes/ImageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SDWebImage
class ImageManager : ObservableObject {
@Published var image: PlatformImage?
@Published var isLoading: Bool = false
@Published var isIncremental: Bool = false
@Published var progress: CGFloat = 0

var manager = SDWebImageManager.shared
Expand Down Expand Up @@ -56,6 +57,7 @@ class ImageManager : ObservableObject {
if let image = image {
self.image = image
}
self.isIncremental = !finished
if finished {
self.isLoading = false
self.progress = 1
Expand Down
9 changes: 6 additions & 3 deletions SDWebImageSwiftUI/Classes/WebImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI
import SDWebImage

public struct WebImage : View {
static var emptyImage = Image(platformImage: PlatformImage())
static var emptyImage = PlatformImage()

var url: URL?
var placeholder: Image?
Expand Down Expand Up @@ -46,7 +46,7 @@ public struct WebImage : View {
let view = image
return AnyView(view)
} else {
var image = placeholder ?? WebImage.emptyImage
var image = placeholder ?? Image(platformImage: WebImage.emptyImage)
image = configurations.reduce(image) { (previous, configuration) in
configuration(previous)
}
Expand All @@ -57,7 +57,10 @@ public struct WebImage : View {
}
}
.onDisappear {
self.imageManager.cancel()
// When using prorgessive loading, the previous partial image will cause onDisappear. Filter this case
if self.imageManager.isLoading && !self.imageManager.isIncremental {
self.imageManager.cancel()
}
}
return AnyView(view)
}
Expand Down