Skip to content

Commit 3f6333c

Browse files
ampagenttmm
andcommitted
fix(zbugs-swift): keep a row's labels whole in a narrow list
On a Mac the list column is narrow enough that the labels were squeezed to a letter or two. They keep their size, and go below the subtitle when they don't fit beside it. Amp-Thread-ID: https://ampcode.com/threads/T-c513a037-a257-45e0-b9a9-15c15edfe859 Co-authored-by: tmm <tmm@tmm.dev>
1 parent 7986f5a commit 3f6333c

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

‎apps/zbugs-swift/Sources/ZBugsUI/IssueList.swift‎

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,21 @@
7474
.foregroundStyle(issue.open ? Color.green : Color.purple)
7575
Text(issue.title).font(.headline).lineLimit(2)
7676
}
77-
HStack(spacing: 6) {
78-
// On one line, before the labels.
79-
Text(issue.subtitle).lineLimit(1).layoutPriority(1)
80-
ForEach(issue.labels ?? [], id: \.id) { label in
81-
Text(label.name)
82-
.lineLimit(1)
83-
.padding(.horizontal, 6)
84-
.background(.quaternary, in: Capsule())
77+
Group {
78+
if (issue.labels ?? []).isEmpty {
79+
subtitle
80+
} else {
81+
// The labels after the subtitle, or below it in a narrow column.
82+
ViewThatFits(in: .horizontal) {
83+
HStack(spacing: 6) {
84+
subtitle
85+
labels
86+
}
87+
VStack(alignment: .leading, spacing: 4) {
88+
subtitle
89+
HStack(spacing: 6) { labels }
90+
}
91+
}
8592
}
8693
}
8794
.font(.caption)
@@ -91,6 +98,20 @@
9198
.accessibilityElement(children: .combine)
9299
.accessibilityIdentifier("IssueRow")
93100
}
101+
102+
private var subtitle: some View {
103+
Text(issue.subtitle).lineLimit(1)
104+
}
105+
106+
/// Whole, never squeezed.
107+
private var labels: some View {
108+
ForEach(issue.labels ?? [], id: \.id) { label in
109+
Text(label.name)
110+
.padding(.horizontal, 6)
111+
.background(.quaternary, in: Capsule())
112+
.fixedSize()
113+
}
114+
}
94115
}
95116

96117
extension Issue {

0 commit comments

Comments
 (0)