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", "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,19 @@ 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 if options.contains(.fromLoaderOnly) {
var context = self.context // If user indeed ignore cache, don't do prefetch
if let result = manager.optionsProcessor?.processedResult(for: url, options: options, context: context) { return
context = result.context
} }
// TODO: Remove transformer for cache calculation before SDWebImage 5.7.0, this is bug. Remove later // Use `.fromCacheOnly` to query cache only
let transformer = (context?[.imageTransformer] as? SDImageTransformer) ?? manager.transformer options.insert(.fromCacheOnly)
context?[.imageTransformer] = nil var context = self.context ?? [:]
// TODO: before SDWebImage 5.7.0, this is the SPI. Remove later context[.queryCacheType] = SDImageCacheType.memory.rawValue
var key: String? // Use `.queryCacheType` to query memory cache only
let selector = Selector(("cacheKeyForURL:context:")) manager.loadImage(with: url, options: options, context: context, progress: nil) { (image, data, error, cacheType, finished, imageUrl) in
if manager.responds(to: selector) { // This will callback immediately
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)
}
}
}
}
} }
} }