From 1b06ca0dcdbda2d801d4aa0f593e56284205702a Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Mon, 5 Oct 2026 14:34:39 +0200 Subject: [PATCH] Let TitleAndIcon take an attributed subtitle Add an AttributedString subtitle initialiser to Compound's TitleAndIcon, with the existing String initialiser forwarding to it so current call sites are unchanged. Add a preview state with a bold run and re-record the titleAndIcon snapshots. This lets screens with partially bold copy, such as the multi-account announcement, use TitleAndIcon instead of rebuilding its layout. --- .../Compound/Components/TitleAndIcon.swift | 27 ++++++++++++++++++- .../titleAndIcon.iPad-en-US-0.png | 4 +-- .../titleAndIcon.iPhone-en-US-0.png | 4 +-- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/compound-ios/Sources/Compound/Components/TitleAndIcon.swift b/compound-ios/Sources/Compound/Components/TitleAndIcon.swift index 768b2a247..7efad2927 100644 --- a/compound-ios/Sources/Compound/Components/TitleAndIcon.swift +++ b/compound-ios/Sources/Compound/Components/TitleAndIcon.swift @@ -16,7 +16,7 @@ import SwiftUI /// than it is to add/subtract additional padding to some arbitrary defaults. public struct TitleAndIcon: View { private let title: String - private let subtitle: String? + private let subtitle: AttributedString? private let icon: KeyPath private let iconStyle: BigIcon.Style private let button: ButtonDetails? @@ -26,6 +26,18 @@ public struct TitleAndIcon: View { icon: KeyPath, iconStyle: BigIcon.Style, button: ButtonDetails? = nil) { + self.init(title: title, + subtitle: subtitle.map { AttributedString($0) }, + icon: icon, + iconStyle: iconStyle, + button: button) + } + + public init(title: String, + subtitle: AttributedString?, + icon: KeyPath, + iconStyle: BigIcon.Style, + button: ButtonDetails? = nil) { self.title = title self.subtitle = subtitle self.icon = icon @@ -95,8 +107,21 @@ public struct TitleAndIcon_Previews: PreviewProvider, TestablePreview { icon: \.circle, iconStyle: .defaultSolid, button: .init(title: "Learn more") { }) + + TitleAndIcon(title: "Headline", + subtitle: attributedSubtitle, + icon: \.circle, + iconStyle: .defaultSolid) } .padding(24) .padding(.bottom, 16) } + + private static var attributedSubtitle: AttributedString { + var subtitle = AttributedString("Description with ") + var boldText = AttributedString("bold text") + boldText.inlinePresentationIntent = .stronglyEmphasized + subtitle.append(boldText) + return subtitle + } } diff --git a/compound-ios/Tests/CompoundTests/__Snapshots__/PreviewTests/titleAndIcon.iPad-en-US-0.png b/compound-ios/Tests/CompoundTests/__Snapshots__/PreviewTests/titleAndIcon.iPad-en-US-0.png index 056e20da9..97c6df01b 100644 --- a/compound-ios/Tests/CompoundTests/__Snapshots__/PreviewTests/titleAndIcon.iPad-en-US-0.png +++ b/compound-ios/Tests/CompoundTests/__Snapshots__/PreviewTests/titleAndIcon.iPad-en-US-0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a462bcf49cb01edc5dd987b35fbeed8f22afb1beb821c066aa8b048da5a78285 -size 98742 +oid sha256:3b3d90b0039c941cee3aa00bb89612a1be3582c5de5bee214387e0b6eef744a1 +size 111386 diff --git a/compound-ios/Tests/CompoundTests/__Snapshots__/PreviewTests/titleAndIcon.iPhone-en-US-0.png b/compound-ios/Tests/CompoundTests/__Snapshots__/PreviewTests/titleAndIcon.iPhone-en-US-0.png index bf480a5f0..441e4dc31 100644 --- a/compound-ios/Tests/CompoundTests/__Snapshots__/PreviewTests/titleAndIcon.iPhone-en-US-0.png +++ b/compound-ios/Tests/CompoundTests/__Snapshots__/PreviewTests/titleAndIcon.iPhone-en-US-0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:77ef2e1f94fa765e37b2a51127fe641a60c0049561a32c64ac228665195c0764 -size 56729 +oid sha256:1a8e5eff7ee490a58fc775d54542c26fd3e01a0ba0fddb7f986537243c963818 +size 68065