Fix rendering mode in toolbar button by setting it on the UIImage itself#175
Fix rendering mode in toolbar button by setting it on the UIImage itself#175hartbit wants to merge 1 commit intoSDWebImage:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #175 +/- ##
==========================================
+ Coverage 73.78% 74.13% +0.34%
==========================================
Files 11 11
Lines 965 978 +13
==========================================
+ Hits 712 725 +13
Misses 253 253
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
This simple fix breaks the Vector image (SVG/PDF) and Animated image (GIF/APNG/WebP) for This is because of But I'll try to investigate your demo's issue and provide some solution. |
|
They override the renderingMode Only if your image is inside an TabbarItem, using UIKit's UIToolBarItem. How can I get this context as well (That However, SwiftUI.Image does not need you to do this, they provide the renderingMode for you automatically. |
But |
You're right. It's Bug. See result: Demo: // ContentView.swift
var body: some View {
NavigationView {
WebImage(url: url)
.renderingMode(.original)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button(action: {}, label: {
WebImage()
})
}
}
}
}
// WebImage.swift
// Helper method, just for testing
public static func createUIImage() -> UIImage {
let data = try! Data(contentsOf: URL(string: "https://png-2.findicons.com/files/icons/2118/nuvola/48/help.png")!)
let source = CGImageSourceCreateWithData(data as CFData, nil)!
let cgImage = CGImageSourceCreateImageAtIndex(source, 0, nil)!
let image = UIImage(cgImage: cgImage, scale: 1, orientation: .up)
return image
}Code 1: public var body: some View {
Image(uiImage: WebImage.createUIImage())
}Code 2: public var body: some View {
Image(decorative: WebImage.createUIImage().cgImage!, scale: 1)
}Screenshot: |
|
Fix works well. I'll submit PR and release 2.0.2 |
|
Thanks! Do you plan to open a bug report with Apple or do you want me to do it? |
|
Should be fixed in v2.0.2 |
|
@dreampiggy Thanks again for your the support 👍 |
@hartbit Hi. I think you can submit the bug report to Apple. It's easy to reproduce. https://bugreport.apple.com/web/ Just using this API The demo code is above. The demo is not related to whether use But actually, Apple's team may think this is not a bug ? Because UIImage itself does have a |


When displaying a
WebImageinside aButton, inside aToolbarItem, the rendering mode modifier doesn't work. It looks like a SwiftUI bug, although I wasn't able to reproduce it with plain SwiftUI, with images coming from the asset catalog. Instead, I've found a fix which is to set the rendering mode on theUIImageitself.Here's the code to reproduce the issue:
Note: If you try to reproduce this, you might encounter another SwiftUI bug which seems unrelated: images render at their native size, even when made
resizableand set to a fixed frame.