Skip to content

Upgrade the dependency of SDWebImage 5.7.0 #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "SDWebImage/SDWebImage" ~> 5.3
github "SDWebImage/SDWebImage" ~> 5.7
4 changes: 2 additions & 2 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion SDWebImageSwiftUI.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
48 changes: 11 additions & 37 deletions SDWebImageSwiftUI/Classes/ImageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
// 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)
var options = self.options
if options.contains(.fromLoaderOnly) {
// If user indeed ignore cache, don't do prefetch
return
}
// 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)
}
}
}
}
}
}

Expand Down