CategoryRow.swift


  1. import SwiftUI
  2. struct CategoryRow: View {
  3. var categoryName: String
  4. var items: [Landmark]
  5. var body: some View {
  6. VStack(alignment: .leading) {
  7. Text(categoryName)
  8. .font(.headline)
  9. .padding(.leading, 15)
  10. .padding(.top, 5)
  11. ScrollView(.horizontal, showsIndicators: false) {
  12. HStack(alignment: .top, spacing: 0) {
  13. ForEach(items) { landmark in
  14. Text(landmark.name)
  15. }
  16. }
  17. }
  18. .frame(height: 185)
  19. }
  20. }
  21. }
  22. struct CategoryRow_Previews: PreviewProvider {
  23. static var landmarks = ModelData().landmarks
  24. static var previews: some View {
  25. CategoryRow(
  26. categoryName: landmarks[0].category.rawValue,
  27. items: Array(landmarks.prefix(4))
  28. )
  29. }
  30. }