Skip to content

Commit b927adb

Browse files
committed
Revert the changes to prefetch the image url from memory cache, because there are cases that the onAppear does not get called at all, which need at least update the remote URL. See #105
1 parent 8e61e44 commit b927adb

File tree

2 files changed

+4
-28
lines changed

2 files changed

+4
-28
lines changed

SDWebImageSwiftUI/Classes/ImageManager.swift

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public final class ImageManager : ObservableObject {
2727
var manager: SDWebImageManager
2828
weak var currentOperation: SDWebImageOperation? = nil
2929
var isFirstLoad: Bool = true // false after first call `load()`
30-
var isFirstPrefetch: Bool = true // false after first call `prefetch()`
3130

3231
var url: URL?
3332
var options: SDWebImageOptions
@@ -107,28 +106,6 @@ public final class ImageManager : ObservableObject {
107106
}
108107
}
109108

110-
/// Prefetch the initial state of image, currently query the memory cache only
111-
func prefetch() {
112-
isFirstPrefetch = false
113-
var options = self.options
114-
if options.contains(.fromLoaderOnly) {
115-
// If user indeed ignore cache, don't do prefetch
116-
return
117-
}
118-
// Use `.fromCacheOnly` to query cache only
119-
options.insert(.fromCacheOnly)
120-
var context = self.context ?? [:]
121-
context[.queryCacheType] = SDImageCacheType.memory.rawValue
122-
// Use `.queryCacheType` to query memory cache only
123-
manager.loadImage(with: url, options: options, context: context, progress: nil) { (image, data, error, cacheType, finished, imageUrl) in
124-
// This will callback immediately
125-
self.image = image
126-
if let image = image {
127-
self.successBlock?(image, cacheType)
128-
}
129-
}
130-
}
131-
132109
}
133110

134111
// Completion Handler

SDWebImageSwiftUI/Classes/WebImage.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ public struct WebImage : View {
6060
}
6161

6262
public var body: some View {
63-
// this prefetch the memory cache of image, to immediately render it on screen
64-
// this solve the case when `onAppear` not been called, for example, some transaction indeterminate state, SwiftUI :)
65-
if imageManager.isFirstPrefetch {
66-
imageManager.prefetch()
63+
// This solve the case when WebImage created with new URL, but `onAppear` not been called, for example, some transaction indeterminate state, SwiftUI :)
64+
if imageManager.isFirstLoad {
65+
imageManager.load()
6766
}
6867
return Group {
6968
if imageManager.image != nil {
@@ -100,7 +99,7 @@ public struct WebImage : View {
10099
setupPlaceholder()
101100
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
102101
.onAppear {
103-
// load remote image when first appear
102+
// Load remote image when first appear
104103
if self.imageManager.isFirstLoad {
105104
self.imageManager.load()
106105
return

0 commit comments

Comments
 (0)