LandmarkDetail.swift


  1. import SwiftUI
  2. struct LandmarkDetail: View {
  3. @EnvironmentObject var modelData: ModelData
  4. var landmark: Landmark
  5. var landmarkIndex: Int {
  6. modelData.landmarks.firstIndex(where: { $0.id == landmark.id })!
  7. }
  8. var body: some View {
  9. ScrollView {
  10. VStack {
  11. CircleImage(image: landmark.image.resizable())
  12. .scaledToFit()
  13. Text(landmark.name)
  14. .font(.headline)
  15. .lineLimit(0)
  16. Toggle(isOn: $modelData.landmarks[landmarkIndex].isFavorite) {
  17. Text("Favorite")
  18. }
  19. Divider()
  20. Text(landmark.park)
  21. .font(.caption)
  22. .bold()
  23. .lineLimit(0)
  24. Text(landmark.state)
  25. .font(.caption)
  26. Divider()
  27. MapView(coordinate: landmark.locationCoordinate)
  28. .scaledToFit()
  29. }
  30. .padding(16)
  31. }
  32. .navigationTitle("Landmarks")
  33. }
  34. }
  35. struct LandmarkDetail_Previews: PreviewProvider {
  36. static var previews: some View {
  37. let modelData = ModelData()
  38. return Group {
  39. LandmarkDetail(landmark: modelData.landmarks[0])
  40. .environmentObject(modelData)
  41. .previewDevice("Apple Watch Series 5 - 44mm")
  42. LandmarkDetail(landmark: modelData.landmarks[1])
  43. .environmentObject(modelData)
  44. .previewDevice("Apple Watch Series 5 - 40mm")
  45. }
  46. }
  47. }