CategoryHome.swift


  1. import SwiftUI
  2. struct CategoryHome: View {
  3. @EnvironmentObject var modelData: ModelData
  4. @State private var showingProfile = false
  5. var body: some View {
  6. NavigationView {
  7. List {
  8. modelData.features[0].image
  9. .resizable()
  10. .scaledToFill()
  11. .frame(height: 200)
  12. .clipped()
  13. .listRowInsets(EdgeInsets())
  14. ForEach(modelData.categories.keys.sorted(), id: \.self) { key in
  15. CategoryRow(categoryName: key, items: modelData.categories[key]!)
  16. }
  17. .listRowInsets(EdgeInsets())
  18. }
  19. .navigationTitle("Featured")
  20. .toolbar {
  21. Button(action: { showingProfile.toggle() }) {
  22. Image(systemName: "person.crop.circle")
  23. .accessibilityLabel("User Profile")
  24. }
  25. }
  26. .sheet(isPresented: $showingProfile) {
  27. ProfileHost()
  28. .environmentObject(modelData)
  29. }
  30. }
  31. }
  32. }
  33. struct CategoryHome_Previews: PreviewProvider {
  34. static var previews: some View {
  35. CategoryHome()
  36. .environmentObject(ModelData())
  37. }
  38. }