Merge pull request #93 from SDWebImage/upgrade_sdwebimage_5_7

Upgrade the dependency of SDWebImage 5.7.0
This commit is contained in:
DreamPiggy 2020-04-05 12:43:31 +08:00 committed by GitHub
commit 7458f13329
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 42 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",
"state": {
"branch": null,
"revision": "48909c2a744d9c7d0350398fafc127945e367286",
"version": "5.3.0"
"revision": "e2285181a62daf4d1d3caf66d6d776b667092303",
"version": "5.7.0"
}
}
]

View File

@ -17,7 +17,7 @@ let package = Package(
dependencies: [
// Dependencies declare other packages that this package depends on.
// .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 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.dependency 'SDWebImage', '~> 5.3'
s.dependency 'SDWebImage', '~> 5.7'
s.swift_version = '5.1'
end

View File

@ -110,45 +110,19 @@ public final class ImageManager : ObservableObject {
/// Prefetch the initial state of image, currently query the memory cache only
func prefetch() {
isFirstPrefetch = false
// Use the options processor if provided
let options = self.options
var context = self.context
if let result = manager.optionsProcessor?.processedResult(for: url, options: options, context: context) {
context = result.context
var options = self.options
if options.contains(.fromLoaderOnly) {
// If user indeed ignore cache, don't do prefetch
return
}
// TODO: Remove transformer for cache calculation before SDWebImage 5.7.0, this is bug. Remove later
let transformer = (context?[.imageTransformer] as? SDImageTransformer) ?? manager.transformer
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)
// Use `.fromCacheOnly` to query cache only
options.insert(.fromCacheOnly)
var context = self.context ?? [:]
context[.queryCacheType] = SDImageCacheType.memory.rawValue
// Use `.queryCacheType` to query memory cache only
manager.loadImage(with: url, options: options, context: context, progress: nil) { (image, data, error, cacheType, finished, imageUrl) in
// This will callback immediately
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)
}
}
}
}
}
}