From e72e59dc7612ab0396dba6041086246b0fc0e26a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20G=C3=BCnd=C3=BCz?= Date: Tue, 13 Oct 2026 13:11:20 +0200 Subject: [PATCH] Respect muteContent in HorizontalLabeledContentStyle The style always rendered the content in the secondary style, so `.horizontal(muteContent: false)` had no effect. --- .../HorizontalLabeledContentStyle.swift | 2 +- .../HorizontalLabeledContentStyleTests.swift | 38 +++++++++++++++++++ .../HandySwiftUITests/RenderingHelpers.swift | 10 +++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 Tests/HandySwiftUITests/HorizontalLabeledContentStyleTests.swift create mode 100644 Tests/HandySwiftUITests/RenderingHelpers.swift diff --git a/Sources/HandySwiftUI/Styles/HorizontalLabeledContentStyle.swift b/Sources/HandySwiftUI/Styles/HorizontalLabeledContentStyle.swift index 9a4eba9..df236ec 100644 --- a/Sources/HandySwiftUI/Styles/HorizontalLabeledContentStyle.swift +++ b/Sources/HandySwiftUI/Styles/HorizontalLabeledContentStyle.swift @@ -11,7 +11,7 @@ public struct HorizontalLabeledContentStyle: LabeledContentStyle { Spacer() configuration.content - .foregroundStyle(.secondary) + .applyIf(self.muteContent) { $0.foregroundStyle(.secondary) } } } } diff --git a/Tests/HandySwiftUITests/HorizontalLabeledContentStyleTests.swift b/Tests/HandySwiftUITests/HorizontalLabeledContentStyleTests.swift new file mode 100644 index 0000000..a7d40ab --- /dev/null +++ b/Tests/HandySwiftUITests/HorizontalLabeledContentStyleTests.swift @@ -0,0 +1,38 @@ +import SwiftUI +import Testing + +@testable import HandySwiftUI + +@MainActor +struct HorizontalLabeledContentStyleTests { + func labeledContent(muteContent: Bool) -> some View { + LabeledContent { + Text(verbatim: "Content") + } label: { + Text(verbatim: "Label") + } + .labeledContentStyle(.horizontal(muteContent: muteContent)) + .frame(width: 200) + } + + func reference(contentStyle: HierarchicalShapeStyle) -> some View { + HStack { + Text(verbatim: "Label") + Spacer() + Text(verbatim: "Content").foregroundStyle(contentStyle) + } + .frame(width: 200) + } + + @Test + func mutedContentIsSecondary() throws { + let muted = try #require(renderedPixels(of: self.labeledContent(muteContent: true))) + #expect(muted == renderedPixels(of: self.reference(contentStyle: .secondary))) + } + + @Test + func unmutedContentIsPrimary() throws { + let unmuted = try #require(renderedPixels(of: self.labeledContent(muteContent: false))) + #expect(unmuted == renderedPixels(of: self.reference(contentStyle: .primary))) + } +} diff --git a/Tests/HandySwiftUITests/RenderingHelpers.swift b/Tests/HandySwiftUITests/RenderingHelpers.swift new file mode 100644 index 0000000..0189181 --- /dev/null +++ b/Tests/HandySwiftUITests/RenderingHelpers.swift @@ -0,0 +1,10 @@ +import SwiftUI + +/// Renders a view into raw pixel data so that two renderings can be compared for equality. +@MainActor +func renderedPixels(of view: some View) -> Data? { + let renderer = ImageRenderer(content: view) + renderer.scale = 1 + guard let cgImage = renderer.cgImage else { return nil } + return cgImage.dataProvider?.data as Data? +}