Created
May 4, 2020 06:34
-
-
Save Dimillian/ab6dc0028bfcac263fdfc2ce69ef0601 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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