From 653311c8c312849e1613c763587abbdff04ea208 Mon Sep 17 00:00:00 2001 From: Rakuyo Date: Mon, 17 Jun 2024 20:06:00 +0800 Subject: [PATCH] feat: Add `color` for `FastImageContentProviding.sfSymbols` method --- Sources/Epoxy/Row/ButtonRow/AnyButtonImageContent.swift | 6 ++++-- Sources/Epoxy/Row/ImageRow/AnyImageContent.swift | 6 ++++-- Sources/Epoxy/Row/ImageRow/FastImageContentProviding.swift | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/Epoxy/Row/ButtonRow/AnyButtonImageContent.swift b/Sources/Epoxy/Row/ButtonRow/AnyButtonImageContent.swift index 536822c..4fae138 100644 --- a/Sources/Epoxy/Row/ButtonRow/AnyButtonImageContent.swift +++ b/Sources/Epoxy/Row/ButtonRow/AnyButtonImageContent.swift @@ -54,8 +54,10 @@ extension AnyButtonImageContent: FastImageContentProviding { .init(UIImage(contentsOfFile: path)) } - public static func sfSymbols(name: String, configuration: UIImage.SymbolConfiguration? = nil) -> Self { - .init(UIImage(systemName: name, withConfiguration: configuration)) + public static func sfSymbols(name: String, color: UIColor? = nil, configuration: UIImage.SymbolConfiguration? = nil) -> Self { + let image = UIImage(systemName: name, withConfiguration: configuration) + let finalImage = color.flatMap { image?.withTintColor($0, renderingMode: .alwaysOriginal) } ?? image + return .init(finalImage) } } #endif diff --git a/Sources/Epoxy/Row/ImageRow/AnyImageContent.swift b/Sources/Epoxy/Row/ImageRow/AnyImageContent.swift index abd109b..5c5ce4d 100644 --- a/Sources/Epoxy/Row/ImageRow/AnyImageContent.swift +++ b/Sources/Epoxy/Row/ImageRow/AnyImageContent.swift @@ -54,8 +54,10 @@ extension AnyImageContent: FastImageContentProviding { .init(UIImage(contentsOfFile: path)) } - public static func sfSymbols(name: String, configuration: UIImage.SymbolConfiguration? = nil) -> Self { - .init(UIImage(systemName: name, withConfiguration: configuration)) + public static func sfSymbols(name: String, color: UIColor? = nil, configuration: UIImage.SymbolConfiguration? = nil) -> Self { + let image = UIImage(systemName: name, withConfiguration: configuration) + let finalImage = color.flatMap { image?.withTintColor($0, renderingMode: .alwaysOriginal) } ?? image + return .init(finalImage) } } #endif diff --git a/Sources/Epoxy/Row/ImageRow/FastImageContentProviding.swift b/Sources/Epoxy/Row/ImageRow/FastImageContentProviding.swift index f5ee934..61de1af 100644 --- a/Sources/Epoxy/Row/ImageRow/FastImageContentProviding.swift +++ b/Sources/Epoxy/Row/ImageRow/FastImageContentProviding.swift @@ -12,5 +12,5 @@ public protocol FastImageContentProviding { static func asset(name: String, bundle: Bundle, with configuration: UIImage.Configuration?) -> Self static func data(_ data: Data) -> Self static func file(path: String) -> Self - static func sfSymbols(name: String, configuration: UIImage.SymbolConfiguration?) -> Self + static func sfSymbols(name: String, color: UIColor?, configuration: UIImage.SymbolConfiguration?) -> Self }