-
Notifications
You must be signed in to change notification settings - Fork 3
/
ContentView.swift
69 lines (61 loc) · 2.1 KB
/
ContentView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// ContentView.swift
// P19C SnowSeeker
//
// Created by Julian Moorhouse on 20/05/2021.
//
import SwiftUI
struct ContentView: View {
@ObservedObject var favourites = Favourites()
let resorts: [Resort] = Bundle.main.decode("resorts.json")
var body: some View {
NavigationView {
List(resorts) { resort in
NavigationLink(destination: ResortView(resort: resort)) {
Image(resort.country)
.resizable()
.scaledToFill()
.frame(width: 40, height: 25)
.clipShape(
RoundedRectangle(cornerRadius: 5)
)
.overlay(
RoundedRectangle(cornerRadius: 5)
.stroke(Color.black, lineWidth: 1)
)
VStack(alignment: .leading) {
Text(resort.name)
.font(.headline)
Text("\(resort.runs) runs")
.foregroundColor(.secondary)
}
.layoutPriority(1)
if self.favourites.contains(resort) {
Spacer()
Image(systemName: "heart.fill")
.accessibility(label: Text("This is a favourite resort"))
.foregroundColor(.red)
}
}
}
.navigationBarTitle("Resorts")
WelcomeView()
}
.environmentObject(favourites)
//.phoneOnlyStackNavigationView()
}
}
extension View {
func phoneOnlyStackNavigationView() -> some View {
if UIDevice.current.userInterfaceIdiom == .phone {
return AnyView(self.navigationViewStyle(StackNavigationViewStyle()))
} else {
return AnyView(self)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}