Skip to content

Commit f1279a5

Browse files
authored
Merge pull request #11 from FlineDev/wip/convertible-symbol-metadata
Strip symbol metadata in Image and Label convertible initializers
2 parents 343a732 + dd410f3 commit f1279a5

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎Sources/HandySwiftUI/Extensions/ImageExt.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension Image {
2121
/// let imageView = Image(convertible: symbol)
2222
/// ```
2323
public init(convertible: CustomSymbolConvertible, variableValue: Double? = nil) {
24-
self.init(systemName: convertible.symbolName, variableValue: variableValue)
24+
self.init(systemName: convertible.symbolSystemName, variableValue: variableValue)
2525
}
2626
}
2727

‎Sources/HandySwiftUI/Extensions/LabelExt.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ extension Label<Text, Image> {
1919
/// // Creates a Label with "Settings" text and a gear icon
2020
/// ```
2121
public init(convertible: CustomLabelConvertible) {
22-
self.init(convertible.description, systemImage: convertible.symbolName)
22+
self.init(convertible.description, systemImage: convertible.symbolSystemName)
2323
}
2424
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import SwiftUI
2+
import Testing
3+
4+
@testable import HandySwiftUI
5+
6+
@MainActor
7+
struct ConvertibleTests {
8+
struct RotatedStar: CustomLabelConvertible {
9+
var description: String { "Rotated Star" }
10+
var symbolName: String { "star:45*2" }
11+
}
12+
13+
@Test
14+
func imageUsesTheSymbolNameWithoutMetadata() {
15+
#expect(Image(convertible: RotatedStar()) == Image(systemName: "star"))
16+
}
17+
18+
@Test
19+
func labelUsesTheSymbolNameWithoutMetadata() throws {
20+
let label = Label(convertible: RotatedStar())
21+
let icon = try #require(Mirror(reflecting: label).children.first { $0.label == "icon" }?.value as? Image)
22+
23+
#expect(icon == Image(systemName: "star"))
24+
}
25+
}

0 commit comments

Comments
 (0)