File tree Expand file tree Collapse file tree 3 files changed +9
-3
lines changed
Example/SDWebImageSwiftUIDemo
SDWebImageSwiftUI/Classes Expand file tree Collapse file tree 3 files changed +9
-3
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import SDWebImage
1212class 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
@@ -57,6 +58,7 @@ class ImageManager : ObservableObject {
5758 if let image = image {
5859 self . image = image
5960 }
61+ self . isIncremental = !finished
6062 if finished {
6163 self . isLoading = false
6264 self . progress = 1
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import SwiftUI
1010import SDWebImage
1111
1212public 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 }
You can’t perform that action at this time.
0 commit comments