Upgrade the dependency of SDWebImage 5.7.0

This commit is contained in:
DreamPiggy 2020-04-04 19:06:23 +08:00
parent 395f0e61f9
commit d07a405bb5
5 changed files with 13 additions and 43 deletions

View File

@ -1 +1 @@
github "SDWebImage/SDWebImage" ~> 5.3 github "SDWebImage/SDWebImage" ~> 5.7

View File

@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/SDWebImage/SDWebImage.git", "repositoryURL": "https://github.com/SDWebImage/SDWebImage.git",
"state": { "state": {
"branch": null, "branch": null,
"revision": "48909c2a744d9c7d0350398fafc127945e367286", "revision": "e2285181a62daf4d1d3caf66d6d776b667092303",
"version": "5.3.0" "version": "5.7.0"
} }
} }
] ]

View File

@ -17,7 +17,7 @@ let package = Package(
dependencies: [ dependencies: [
// Dependencies declare other packages that this package depends on. // Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"), // .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.3.0") .package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.7.0")
], ],
targets: [ targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets are the basic building blocks of a package. A target can define a module or a test suite.

View File

@ -34,6 +34,6 @@ It brings all your favorite features from SDWebImage, like async image loading,
} }
s.weak_frameworks = 'SwiftUI', 'Combine' s.weak_frameworks = 'SwiftUI', 'Combine'
s.dependency 'SDWebImage', '~> 5.3' s.dependency 'SDWebImage', '~> 5.7'
s.swift_version = '5.1' s.swift_version = '5.1'
end end

View File

@ -110,45 +110,15 @@ public final class ImageManager : ObservableObject {
/// Prefetch the initial state of image, currently query the memory cache only /// Prefetch the initial state of image, currently query the memory cache only
func prefetch() { func prefetch() {
isFirstPrefetch = false isFirstPrefetch = false
// Use the options processor if provided var options = self.options
let options = self.options // use `.fromCacheOnly` to query cache only
var context = self.context options.insert(.fromCacheOnly)
if let result = manager.optionsProcessor?.processedResult(for: url, options: options, context: context) { var context = self.context ?? [:]
context = result.context context[.queryCacheType] = SDImageCacheType.memory.rawValue
} // Use `.queryCacheType` to query memory cache only
// TODO: Remove transformer for cache calculation before SDWebImage 5.7.0, this is bug. Remove later manager.loadImage(with: url, options: options, context: context, progress: nil) { (image, data, error, cacheType, finished, imageUrl) in
let transformer = (context?[.imageTransformer] as? SDImageTransformer) ?? manager.transformer // This will callback immediately
context?[.imageTransformer] = nil
// TODO: before SDWebImage 5.7.0, this is the SPI. Remove later
var key: String?
let selector = Selector(("cacheKeyForURL:context:"))
if manager.responds(to: selector) {
key = manager.perform(selector, with: url, with: context)?.takeUnretainedValue() as? String
} else {
key = manager.cacheKey(for: url)
}
if let transformer = transformer {
key = SDTransformedKeyForKey(key, transformer.transformerKey)
}
// Shortcut for built-in cache
if let imageCache = manager.imageCache as? SDImageCache {
let image = imageCache.imageFromMemoryCache(forKey: key)
self.image = image self.image = image
if let image = image {
self.successBlock?(image, .memory)
}
} else {
// This callback is synchronzied
manager.imageCache.containsImage(forKey: key, cacheType: .memory) { [unowned self] (cacheType) in
if cacheType == .memory {
self.manager.imageCache.queryImage(forKey: key, options: options, context: context) { [unowned self] (image, data, cacheType) in
self.image = image
if let image = image {
self.successBlock?(image, cacheType)
}
}
}
}
} }
} }