diff --git a/Shared/Supporting Files/Views/CategoryGridView.swift b/Shared/Supporting Files/Views/CategoryGridView.swift index 6739e3d06..627c66f95 100644 --- a/Shared/Supporting Files/Views/CategoryGridView.swift +++ b/Shared/Supporting Files/Views/CategoryGridView.swift @@ -38,8 +38,11 @@ struct CategoryGridView: View { LazyVGrid(columns: columns) { ForEach(categories, id: \.self) { category in NavigationLink { - SampleListView(samples: samples.filter { $0.category == category }) - .navigationTitle(category) + SampleListView( + samples: samples.filter { $0.category == category }, + shouldShowCategory: false + ) + .navigationTitle(category) } label: { CategoryTitleView(category: category) } diff --git a/Shared/Supporting Files/Views/CategoryView.swift b/Shared/Supporting Files/Views/CategoryView.swift index 2e7d19380..15d8a8778 100644 --- a/Shared/Supporting Files/Views/CategoryView.swift +++ b/Shared/Supporting Files/Views/CategoryView.swift @@ -37,7 +37,7 @@ struct CategoryView: View { if !isSearching { CategoryGridView(samples: samples) } else { - SampleListView(samples: displayedSamples) + SampleListView(samples: displayedSamples, shouldShowCategory: true) } } .navigationTitle("Samples") diff --git a/Shared/Supporting Files/Views/SampleListView.swift b/Shared/Supporting Files/Views/SampleListView.swift index ffaf1d6ba..51919af3e 100644 --- a/Shared/Supporting Files/Views/SampleListView.swift +++ b/Shared/Supporting Files/Views/SampleListView.swift @@ -18,9 +18,14 @@ struct SampleListView: View { /// All samples that will be displayed in the list. let samples: [Sample] + /// A Boolean value indicating whether the row description should include + /// the sample's category. We only need this information when the samples + /// in the list are from different categories. + let shouldShowCategory: Bool + var body: some View { List(samples, id: \.name) { sample in - SampleRow(sample: sample) + SampleRow(sample: sample, shouldShowCategory: shouldShowCategory) } } } @@ -30,32 +35,25 @@ private extension SampleListView { /// The sample displayed in the row. let sample: Sample - /// A Boolean value that indicates whether to show the sample's description. - @State private var isShowingDescription = false + /// A Boolean value that indicates whether to show the sample's category. + let shouldShowCategory: Bool var body: some View { - NavigationLink { - SampleDetailView(sample: sample) - } label: { - HStack { - VStack(alignment: .leading, spacing: 5) { - Text(sample.name) - if isShowingDescription { - Text(sample.description) - .font(.caption) - .foregroundColor(.secondary) - .transition(.move(edge: .top).combined(with: .opacity)) - } - } - Spacer() - Button { - isShowingDescription.toggle() - } label: { - Image(systemName: isShowingDescription ? "info.circle.fill" : "info.circle") + DisclosureGroup { + VStack(alignment: .leading) { + if shouldShowCategory { + Text("Category: \(sample.category)") + .bold() } - .buttonStyle(.borderless) + Text(sample.description) + .foregroundColor(.secondary) + } + .listRowSeparator(.hidden) + .font(.caption) + } label: { + NavigationLink(sample.name) { + SampleDetailView(sample: sample) } - .animation(.easeOut(duration: 0.2), value: isShowingDescription) } } }