Update the Example to showing the capability to load PDF/SVG on tvOS/macOS/watchOS as well

This commit is contained in:
DreamPiggy 2020-01-30 11:58:05 +08:00
parent e46e21ba41
commit 0cde522360
4 changed files with 40 additions and 2 deletions

View File

@ -36,6 +36,20 @@ class AppDelegate: NSObject, NSApplicationDelegate {
SDImageCodersManager.shared.addCoder(SDImageWebPCoder.shared)
SDImageCodersManager.shared.addCoder(SDImageSVGCoder.shared)
SDImageCodersManager.shared.addCoder(SDImagePDFCoder.shared)
// Dynamic check to support vector format for both WebImage/AnimatedImage
SDWebImageManager.shared.optionsProcessor = SDWebImageOptionsProcessor { url, options, context in
var options = options
var context = context
if let _ = context?[.animatedImageClass] as? SDAnimatedImage.Type {
// AnimatedImage supports vector rendering, should not force decode
options.insert(.avoidDecodeImage)
} else {
// WebImage supports bitmap rendering only
context?[.svgPrefersBitmap] = true
context?[.pdfPrefersBitmap] = true
}
return SDWebImageOptionsResult(options: options, context: context)
}
}
func applicationWillTerminate(_ aNotification: Notification) {

View File

@ -33,6 +33,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
SDImageCodersManager.shared.addCoder(SDImageWebPCoder.shared)
SDImageCodersManager.shared.addCoder(SDImageSVGCoder.shared)
SDImageCodersManager.shared.addCoder(SDImagePDFCoder.shared)
// Dynamic check to support vector format for both WebImage/AnimatedImage
SDWebImageManager.shared.optionsProcessor = SDWebImageOptionsProcessor { url, options, context in
var options = options
var context = context
if let _ = context?[.animatedImageClass] as? SDAnimatedImage.Type {
// AnimatedImage supports vector rendering, should not force decode
options.insert(.avoidDecodeImage)
} else {
// WebImage supports bitmap rendering only
context?[.svgPrefersBitmap] = true
context?[.pdfPrefersBitmap] = true
}
return SDWebImageOptionsResult(options: options, context: context)
}
return true
}

View File

@ -20,6 +20,14 @@ class ExtensionDelegate: NSObject, WKExtensionDelegate {
SDImageCodersManager.shared.addCoder(SDImageWebPCoder.shared)
SDImageCodersManager.shared.addCoder(SDImageSVGCoder.shared)
SDImageCodersManager.shared.addCoder(SDImagePDFCoder.shared)
// Dynamic check to support vector format for WebImage
SDWebImageManager.shared.optionsProcessor = SDWebImageOptionsProcessor { url, options, context in
var context = context
// WebImage supports bitmap rendering only
context?[.svgPrefersBitmap] = true
context?[.pdfPrefersBitmap] = true
return SDWebImageOptionsResult(options: options, context: context)
}
}
func applicationDidBecomeActive() {

View File

@ -23,11 +23,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
SDImageCodersManager.shared.addCoder(SDImageWebPCoder.shared)
SDImageCodersManager.shared.addCoder(SDImageSVGCoder.shared)
SDImageCodersManager.shared.addCoder(SDImagePDFCoder.shared)
// Dynamic check to support both WebImage/AnimatedImage
// Dynamic check to support vector format for both WebImage/AnimatedImage
SDWebImageManager.shared.optionsProcessor = SDWebImageOptionsProcessor { url, options, context in
var options = options
var context = context
if let _ = context?[.animatedImageClass] as? SDAnimatedImage.Type {
// AnimatedImage supports vector rendering
// AnimatedImage supports vector rendering, should not force decode
options.insert(.avoidDecodeImage)
} else {
// WebImage supports bitmap rendering only
context?[.svgPrefersBitmap] = true