Skip to content

Add support to pass the .customManager context option to custom SDWebImageManager instance #71

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 1 commit into from
Jan 26, 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
8 changes: 4 additions & 4 deletions Example/SDWebImageSwiftUIDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
SDImageCodersManager.shared.addCoder(SDImagePDFCoder.shared)
// Dynamic check to support both WebImage/AnimatedImage
SDWebImageManager.shared.optionsProcessor = SDWebImageOptionsProcessor { url, options, context in
var context = context ?? [:]
if let _ = context[.animatedImageClass] as? SDAnimatedImageProtocol {
var context = context
if let _ = context?[.animatedImageClass] as? SDAnimatedImageProtocol {
// AnimatedImage supports vector rendering
} else {
// WebImage supports bitmap rendering only
context[.svgPrefersBitmap] = true
context[.pdfPrefersBitmap] = true
context?[.svgPrefersBitmap] = true
context?[.pdfPrefersBitmap] = true
}
return SDWebImageOptionsResult(options: options, context: context)
}
Expand Down
7 changes: 6 additions & 1 deletion SDWebImageSwiftUI/Classes/ImageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ImageManager : ObservableObject {
@Published var isLoading: Bool = false // whether network is loading or cache is querying, should only be used for indicator binding
@Published var progress: CGFloat = 0 // network progress, should only be used for indicator binding

var manager = SDWebImageManager.shared
var manager: SDWebImageManager
weak var currentOperation: SDWebImageOperation? = nil
var isSuccess: Bool = false // true means request for this URL is ended forever, load() do nothing
var isIncremental: Bool = false // true means during incremental loading
Expand All @@ -31,6 +31,11 @@ class ImageManager : ObservableObject {
self.url = url
self.options = options
self.context = context
if let manager = context?[.customManager] as? SDWebImageManager {
self.manager = manager
} else {
self.manager = .shared
}
}

func load() {
Expand Down