Skip to content

Commit a416abe

Browse files
authored
Merge pull request #71 from SDWebImage/feature_context_manager
Add support to pass the `.customManager` context option to custom SDWebImageManager instance
2 parents e59739b + f5e222d commit a416abe

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Example/SDWebImageSwiftUIDemo/AppDelegate.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2525
SDImageCodersManager.shared.addCoder(SDImagePDFCoder.shared)
2626
// Dynamic check to support both WebImage/AnimatedImage
2727
SDWebImageManager.shared.optionsProcessor = SDWebImageOptionsProcessor { url, options, context in
28-
var context = context ?? [:]
29-
if let _ = context[.animatedImageClass] as? SDAnimatedImageProtocol {
28+
var context = context
29+
if let _ = context?[.animatedImageClass] as? SDAnimatedImageProtocol {
3030
// AnimatedImage supports vector rendering
3131
} else {
3232
// WebImage supports bitmap rendering only
33-
context[.svgPrefersBitmap] = true
34-
context[.pdfPrefersBitmap] = true
33+
context?[.svgPrefersBitmap] = true
34+
context?[.pdfPrefersBitmap] = true
3535
}
3636
return SDWebImageOptionsResult(options: options, context: context)
3737
}

SDWebImageSwiftUI/Classes/ImageManager.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ImageManager : ObservableObject {
1515
@Published var isLoading: Bool = false // whether network is loading or cache is querying, should only be used for indicator binding
1616
@Published var progress: CGFloat = 0 // network progress, should only be used for indicator binding
1717

18-
var manager = SDWebImageManager.shared
18+
var manager: SDWebImageManager
1919
weak var currentOperation: SDWebImageOperation? = nil
2020
var isSuccess: Bool = false // true means request for this URL is ended forever, load() do nothing
2121
var isIncremental: Bool = false // true means during incremental loading
@@ -31,6 +31,11 @@ class ImageManager : ObservableObject {
3131
self.url = url
3232
self.options = options
3333
self.context = context
34+
if let manager = context?[.customManager] as? SDWebImageManager {
35+
self.manager = manager
36+
} else {
37+
self.manager = .shared
38+
}
3439
}
3540

3641
func load() {

0 commit comments

Comments
 (0)