File tree 3 files changed +9
-3
lines changed
Example/SDWebImageSwiftUIDemo
SDWebImageSwiftUI/Classes
3 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ struct ContentView: View {
29
29
" https://isparta.github.io/compare-webp/image/gif_webp/webp/2.webp " ,
30
30
" https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic " ,
31
31
" https://nokiatech.github.io/heif/content/image_sequences/starfield_animation.heic " ,
32
+ " https://www.sample-videos.com/img/Sample-png-image-1mb.png " ,
32
33
" https://nr-platform.s3.amazonaws.com/uploads/platform/published_extension/branding_icon/275/AmazonS3.png " ,
33
34
" http://via.placeholder.com/200x200.jpg " ]
34
35
@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
12
12
class ImageManager : ObservableObject {
13
13
@Published var image : PlatformImage ?
14
14
@Published var isLoading : Bool = false
15
+ @Published var isIncremental : Bool = false
15
16
@Published var progress : CGFloat = 0
16
17
17
18
var manager = SDWebImageManager . shared
@@ -56,6 +57,7 @@ class ImageManager : ObservableObject {
56
57
if let image = image {
57
58
self . image = image
58
59
}
60
+ self . isIncremental = !finished
59
61
if finished {
60
62
self . isLoading = false
61
63
self . progress = 1
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import SwiftUI
10
10
import SDWebImage
11
11
12
12
public struct WebImage : View {
13
- static var emptyImage = Image ( platformImage : PlatformImage ( ) )
13
+ static var emptyImage = PlatformImage ( )
14
14
15
15
var url : URL ?
16
16
var placeholder : Image ?
@@ -46,7 +46,7 @@ public struct WebImage : View {
46
46
let view = image
47
47
return AnyView ( view)
48
48
} else {
49
- var image = placeholder ?? WebImage . emptyImage
49
+ var image = placeholder ?? Image ( platformImage : WebImage . emptyImage)
50
50
image = configurations. reduce ( image) { ( previous, configuration) in
51
51
configuration ( previous)
52
52
}
@@ -57,7 +57,10 @@ public struct WebImage : View {
57
57
}
58
58
}
59
59
. 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
+ }
61
64
}
62
65
return AnyView ( view)
63
66
}
You can’t perform that action at this time.
0 commit comments