Add a mechanism to customize app icons and colors
This commit is contained in:
@@ -51,7 +51,9 @@ public struct CompoundIcon: View {
|
||||
/// - Parameters:
|
||||
/// - icon: The icon to show.
|
||||
public init(_ icon: KeyPath<CompoundIcons, Image>) {
|
||||
image = .compound[keyPath: icon]
|
||||
// Letro: Add a mechanism to override icons
|
||||
image = Self.resolve(icon)
|
||||
|
||||
size = .medium
|
||||
font = .compound.bodyLG
|
||||
}
|
||||
@@ -63,7 +65,9 @@ public struct CompoundIcon: View {
|
||||
/// - size: The size of the icon.
|
||||
/// - font: The font that should be used for scaling with Dynamic Type.
|
||||
public init(_ icon: KeyPath<CompoundIcons, Image>, size: Size, relativeTo font: Font) {
|
||||
image = .compound[keyPath: icon]
|
||||
// Letro: Add a mechanism to override icons
|
||||
image = Self.resolve(icon)
|
||||
|
||||
self.size = size
|
||||
self.font = font
|
||||
}
|
||||
@@ -102,6 +106,15 @@ public struct CompoundIcon: View {
|
||||
.resizable()
|
||||
.modifier(CompoundIconFrame(fontSize: size.value, textStyle: fontSize.style))
|
||||
}
|
||||
|
||||
// Letro: Add a mechanism to override icons
|
||||
private static var overrides = [AnyKeyPath: Image]()
|
||||
public static func override(_ keyPath: KeyPath<CompoundIcons, Image>, with image: Image?) {
|
||||
overrides[keyPath] = image
|
||||
}
|
||||
private static func resolve(_ keyPath: KeyPath<CompoundIcons, Image>) -> Image {
|
||||
overrides[keyPath] ?? .compound[keyPath: keyPath]
|
||||
}
|
||||
}
|
||||
|
||||
/// A simple modifier that applies a square frame of a given size that will be
|
||||
|
||||
Reference in New Issue
Block a user