Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Update] Add category to sample row #226

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Shared/Supporting Files/Views/CategoryGridView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Shared/Supporting Files/Views/CategoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct CategoryView: View {
if !isSearching {
CategoryGridView(samples: samples)
} else {
SampleListView(samples: displayedSamples)
SampleListView(samples: displayedSamples, shouldShowCategory: true)
dfeinzimer marked this conversation as resolved.
Show resolved Hide resolved
}
}
.navigationTitle("Samples")
Expand Down
44 changes: 21 additions & 23 deletions Shared/Supporting Files/Views/SampleListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand All @@ -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)
}
}
}
Expand Down
Loading