Skip to content

Commit

Permalink
Update the readme about the tint color for AnimatedImage
Browse files Browse the repository at this point in the history
Fix the implementation that breaks the compatible with SDWebImage 5.18+
  • Loading branch information
dreampiggy committed Nov 28, 2023
1 parent ed08143 commit 5ddcdcf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ Note: `AnimatedImage` supports both image url or image data for animated image f

Note: `AnimatedImage` some methods like `.transition`, `.indicator` and `.aspectRatio` have the same naming as `SwiftUI.View` protocol methods. But the args receive the different type. This is because `AnimatedImage` supports to be used with UIKit/AppKit component and animation. If you find ambiguity, use full type declaration instead of the dot expression syntax.

Note: some of methods on `AnimatedImage` will return `some View`, a new Modified Content. You'll lose the type related modifier method. For this case, you can either reorder the method call, or use Native View in `.onViewUpdate` for rescue.
Note: some of methods on `AnimatedImage` will return `some View`, a new Modified Content. You'll lose the type related modifier method. For this case, you can either reorder the method call, or use native view (actually `SDAnimatedImageView`) in `.onViewUpdate`, use UIKIt/AppKit API for rescue.

```swift

Expand Down Expand Up @@ -426,14 +426,30 @@ Both `WebImage/AnimatedImage` supports to render the vector image, by using the
+ `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.
+ `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.

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.
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.

+ WebImage

```swift
var body: some View {
WebImage(url: URL(string: "https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/w3c.svg"))
.resizable()
.renderingMode(.template)
.foregroundColor(.red)
.foregroundColor(.red) // or `.tint(:)`, `.accentColor(:)`
.scaledToFit()
}
```

+ AnimatedImage

```swift
var body: some View {
AnimatedImage(url: URL(string: "https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/w3c.svg"), context: [.imageThumbnailPixelSize : CGSize(width: 100, height: 100)])
.resizable()
.renderingMode(.template)
// seems `.foregroundColor(:)` does effect `UIView.tintColor`, use `tint(:)` or `.accentColor(:)` instead.
// Or you can use `onViewCreate(:)` to get native `SDAnimatedImageView` and set `tintColor` (AppKit use `contentTintColor`)
.tint(.red)
.scaledToFit()
}
```
Expand Down
2 changes: 1 addition & 1 deletion SDWebImageSwiftUI/Classes/AnimatedImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public struct AnimatedImage : PlatformViewRepresentable {
}

// Animated Image does not support resizing mode and rendering mode
if let image = view.wrapped.image, !image.conforms(to: SDAnimatedImageProtocol.self) {
if let image = view.wrapped.image {
var image = image
// ResizingMode
if let resizingMode = imageLayout.resizingMode, imageLayout.capInsets != EdgeInsets() {
Expand Down

0 comments on commit 5ddcdcf

Please sign in to comment.