-
Notifications
You must be signed in to change notification settings - Fork 3
/
ContentView.swift
55 lines (49 loc) · 1.67 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
//
// ContentView.swift
// P08D Moonshot
//
// Created by Julian Moorhouse on 19/02/2021.
//
import SwiftUI
struct ContentView: View {
let astronauts: [Astronaut] = Bundle.main.decode("astronauts.json")
let missions: [Mission] = Bundle.main.decode("missions.json")
@State private var showDetailLaunchDate = false
var body: some View {
NavigationView {
List(missions) { mission in
NavigationLink(destination:
MissionView(mission: mission,
astronauts: self.astronauts,
missions: self.missions)) {
Image(mission.image)
.resizable()
.scaledToFit()
.aspectRatio(contentMode: .fit)
.frame(width: 44, height: 44)
VStack(alignment: .leading) {
Text(mission.displayName)
.font(.headline)
Text(!self.showDetailLaunchDate ?
mission.formattedLaunchDate :
mission.crewDisplay)
.foregroundColor(.secondary)
}
}
}
.navigationBarTitle("Moonshot")
.navigationBarItems(trailing:
Button(self.showDetailLaunchDate ?
"Show Dates" :
"Show Crew") {
self.showDetailLaunchDate.toggle()
}
)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}