File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed
SDWebImageSwiftUI/Classes Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ class ImageManager : ObservableObject {
19
19
weak var currentOperation : SDWebImageOperation ? = nil
20
20
var isSuccess : Bool = false // true means request for this URL is ended forever, load() do nothing
21
21
var isIncremental : Bool = false // true means during incremental loading
22
+ var isFirstLoad : Bool = true // false after first call `load()`
22
23
23
24
var url : URL ?
24
25
var options : SDWebImageOptions
@@ -39,6 +40,7 @@ class ImageManager : ObservableObject {
39
40
}
40
41
41
42
func load( ) {
43
+ isFirstLoad = false
42
44
if currentOperation != nil {
43
45
return
44
46
}
Original file line number Diff line number Diff line change @@ -58,13 +58,16 @@ public struct WebImage : View {
58
58
}
59
59
}
60
60
self . imageManager = ImageManager ( url: url, options: options, context: context)
61
- // load remote image here, SwiftUI sometimes will create a new View struct without calling `onAppear` (like enter EditMode) :)
62
- // this can ensure we load the image, SDWebImage take care of the duplicated query
63
- self . imageManager. load ( )
64
61
}
65
62
66
63
public var body : some View {
67
- Group {
64
+ // load remote image when first called `body`, SwiftUI sometimes will create a new View struct without calling `onAppear` (like enter EditMode) :)
65
+ // this can ensure we load the image, and display image synchronously when memory cache hit to avoid flashing
66
+ // called once per struct, SDWebImage take care of the duplicated query
67
+ if imageManager. isFirstLoad {
68
+ imageManager. load ( )
69
+ }
70
+ return Group {
68
71
if imageManager. image != nil {
69
72
if isAnimating && !self . imageManager. isIncremental {
70
73
if currentFrame != nil {
You can’t perform that action at this time.
0 commit comments