Skip to content

Instantly share code, notes, and snippets.

@Dimillian
Created May 4, 2020 06:34
Show Gist options
  • Save Dimillian/ab6dc0028bfcac263fdfc2ce69ef0601 to your computer and use it in GitHub Desktop.
Save Dimillian/ab6dc0028bfcac263fdfc2ce69ef0601 to your computer and use it in GitHub Desktop.
struct HomeView: View {
@EnvironmentObject private var items: Items
private var categories: [(Backend.Category, [Item])] {
items.categories
.map { $0 }
.sorted(by: \.key.rawValue)
.reversed()
}
private func categorySection(category: Backend.Category, items: [Item]) -> some View {
Section(header: Text(category.label())) {
ScrollView(.horizontal) {
HStack {
ForEach(items.prefix(10)) { item in
ItemRow(item: item)
}
}.frame(height: 220)
}
}
}
var body: some View {
NavigationView {
List {
ForEach(categories, id: \.0, content: categorySection)
}.navigationBarTitle(Text("Items home"))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment