Skip to content

Fix rendering mode in toolbar button by setting it on the UIImage itself #175

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

Closed
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
25 changes: 24 additions & 1 deletion SDWebImageSwiftUI/Classes/WebImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public struct WebImage : View {
var placeholder: AnyView?
var retryOnAppear: Bool = true
var cancelOnDisappear: Bool = true

#if !os(macOS)
var renderingMode: UIImage.RenderingMode? = nil
#endif

@ObservedObject var imageManager: ImageManager

Expand Down Expand Up @@ -123,6 +127,12 @@ public struct WebImage : View {
#if os(macOS)
result = Image(nsImage: image)
#else
var image = image

if let renderingMode = self.renderingMode {
image = image.withRenderingMode(renderingMode)
}

// Fix the SwiftUI.Image rendering issue, like when use EXIF UIImage, the `.aspectRatio` does not works. SwiftUI's Bug :)
// See issue #101
var cgImage: CGImage?
Expand Down Expand Up @@ -209,7 +219,20 @@ extension WebImage {
/// Configurate this view's rendering mode.
/// - Parameter renderingMode: The resizing mode
public func renderingMode(_ renderingMode: Image.TemplateRenderingMode?) -> WebImage {
configure { $0.renderingMode(renderingMode) }
var result = configure { $0.renderingMode(renderingMode) }

#if !os(macOS)
switch renderingMode {
case .original:
result.renderingMode = .alwaysOriginal
case .template:
result.renderingMode = .alwaysTemplate
case nil:
result.renderingMode = .automatic
}
#endif

return result
}

/// Configurate this view's image interpolation quality
Expand Down