Skip to content

Commit

Permalink
Update the Example to showing the capability to load PDF/SVG on tvOS/…
Browse files Browse the repository at this point in the history
…macOS/watchOS as well
  • Loading branch information
dreampiggy committed Jan 30, 2020
1 parent e46e21b commit 0f6eff4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Example/SDWebImageSwiftUIDemo-macOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ class AppDelegate: NSObject, NSApplicationDelegate {
SDImageCodersManager.shared.addCoder(SDImageWebPCoder.shared)
SDImageCodersManager.shared.addCoder(SDImageSVGCoder.shared)
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? SDAnimatedImage.Type {
// AnimatedImage supports vector rendering
} else {
// WebImage supports bitmap rendering only
context?[.svgPrefersBitmap] = true
context?[.pdfPrefersBitmap] = true
}
return SDWebImageOptionsResult(options: options, context: context)
}
}

func applicationWillTerminate(_ aNotification: Notification) {
Expand Down
12 changes: 12 additions & 0 deletions Example/SDWebImageSwiftUIDemo-tvOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ 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
SDWebImageManager.shared.optionsProcessor = SDWebImageOptionsProcessor { url, options, context in
var context = context
if let _ = context?[.animatedImageClass] as? SDAnimatedImage.Type {
// AnimatedImage supports vector rendering
} else {
// WebImage supports bitmap rendering only
context?[.svgPrefersBitmap] = true
context?[.pdfPrefersBitmap] = true
}
return SDWebImageOptionsResult(options: options, context: context)
}

return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 both WebImage/AnimatedImage
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() {
Expand Down

0 comments on commit 0f6eff4

Please sign in to comment.