Skip to content

Commit 6f693bb

Browse files
committed
Update the readme about the tint color for AnimatedImage
Fix the implementation that breaks the compatible with SDWebImage 5.18+
1 parent ed08143 commit 6f693bb

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,30 @@ Both `WebImage/AnimatedImage` supports to render the vector image, by using the
426426
+ `AnimatedImage`: use tech from Apple's symbol image and vector drawing, supports dynamic size changes without lossing details. And it use UIKit/AppKit based implementation and APIs. If you want, pass `.context(.imageThumbnailPixelSize: size)` to use bitmap rendering and get more pixels.
427427
+ `WebImage`: draws vector image into a bitmap version. Which just like normal PNG. By default, we use vector image content size (SVG canvas size or PDF media box size). If you want, pass `.context(.imageThumbnailPixelSize: size)` to get more pixels.
428428

429-
For `WebImage` (or bitmap rendering on `AnimatedImage`), you can also tint the SVG/PDF icons with custom colors (like symbol images), use the `.renderingMode(.template)` and `.foregroundColor(color)` modifier, which matches `SwiftUI.Image` behavior.
429+
For bitmap rendering, you can also tint the SVG/PDF icons with custom colors (like symbol images), use the `.renderingMode(.template)` and `.tint(:)` or `.foreground(:)` modifier, which matches `SwiftUI.Image` behavior.
430+
431+
+ WebImage
430432

431433
```swift
432434
var body: some View {
433435
WebImage(url: URL(string: "https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/w3c.svg"))
434436
.resizable()
435437
.renderingMode(.template)
436-
.foregroundColor(.red)
438+
.foregroundColor(.red) // or `.tint(:)`, `.accentColor(:)`
439+
.scaledToFit()
440+
}
441+
```
442+
443+
+ AnimatedImage
444+
445+
```swift
446+
var body: some View {
447+
AnimatedImage(url: URL(string: "https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/w3c.svg"), context: [.imageThumbnailPixelSize : CGSize(width: 100, height: 100)])
448+
.resizable()
449+
.renderingMode(.template)
450+
// seems `.foregroundColor(:)` does effect `UIView.tintColor`, use `tint(:)` or `.accentColor(:)` instead.
451+
// Or you can use `onViewCreate(:)` to get native UIView and set `tintColor` (AppKit use `contentTintColor`)
452+
.tint(.red)
437453
.scaledToFit()
438454
}
439455
```

SDWebImageSwiftUI/Classes/AnimatedImage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
418418
}
419419

420420
// Animated Image does not support resizing mode and rendering mode
421-
if let image = view.wrapped.image, !image.conforms(to: SDAnimatedImageProtocol.self) {
421+
if let image = view.wrapped.image {
422422
var image = image
423423
// ResizingMode
424424
if let resizingMode = imageLayout.resizingMode, imageLayout.capInsets != EdgeInsets() {

0 commit comments

Comments
 (0)