``` // // ContentView.swift // spacex // // Created by Charlie Kingsland on 20/01/2021. // import SwiftUI import SDWebImage import HalfModal import Foundation struct ContentView: View { @State var launches: [Launch] = [] @State var rockets: [Rocket] = [] // @State private var showingAlert = false @State private var show_modal: Bool = false @State private var mName: String = "" @State private var mDate: String = "" @State private var rID: String = "" @State private var mImg: String = "" @State private var mDesc: String = "" @State private var mYT: String = "" @State private var ytBool: Bool = false @State private var rName: String = "" @State private var showingHalfModal: Bool = false @State private var showingHalfModal2: Bool = false var rocketNames = ["5e9d0d95eda69955f709d1eb": "Falcon 1", "5e9d0d95eda69973a809d1ec": "Falcon 9", "5e9d0d95eda69974db09d1ed": "Falcon Heavy", "5e9d0d96eda699382d09d1ee": "Starship"] var rocketIcons = ["Falcon 1": "spx", "Falcon 9": "f9", "Falcon Heavy": "fh", "Starship": "spx"] init() { UITableView.appearance().separatorStyle = .none UITableViewCell.appearance().backgroundColor = .clear UITableView.appearance().backgroundColor = .clear } var body: some View { // Spacer() // .frame(height: 100) TabView { Group { ZStack { NavigationView { VStack { // Spacer() // .frame(height: 10) // Text("SpaceX launch list") // .font(.largeTitle) Spacer() .frame(height: 1) .navigationBarTitle("Launches") List { ForEach(launches, id: \.id) { launch in // Text("image") // Image("imagenotfound") Button(action: { self.mName = launch.name self.mDate = Date(timeIntervalSince1970: launch.date_unix).getFormattedDate(format: "dd/MM/yyyy HH:mm:ss") self.rID = launch.rocket self.mImg = launch.links.patch.missionPatch ?? "null" self.mDesc = launch.details ?? "No description" self.mYT = launch.links.youtube_id ?? "none" if self.mYT == "none" { self.ytBool = false } else { self.ytBool = true } // sleep(1) self.show_modal.toggle() withAnimation { self.showingHalfModal = true } }) { HStack { // Image("imagenotfound") // .resizable() // .frame(width: 50, height: 50) URLimageView(urlString: launch.links.patch.missionPatch) // .frame(width: 50, height: 50) Group { Text(launch.name) .font(.system(size: 23)) .frame(maxWidth: .infinity, alignment: .leading) .fixedSize(horizontal: false, vertical: true) Text(Date(timeIntervalSince1970: launch.date_unix).getFormattedDate(format: "dd/MM/yyyy HH:mm:ss")) .font(.system(size: 11.5)) .foregroundColor(Color.gray) .frame(maxWidth: .infinity, alignment: .leading) .fixedSize(horizontal: false, vertical: true) Spacer() } } } .buttonStyle(PlainButtonStyle()) } } }.onAppear { apiCall().getUsers{ (launches) in self.launches = launches} }.listStyle(SidebarListStyle()) .frame(alignment: .center) } } if showingHalfModal { HalfModalView(content: AnyView(HStack { VStack { Text(mDesc) .padding() Link("Watch webcast", destination: URL(string: "https://www.youtube.com/watch?v=" + mYT)!) .disabled(!ytBool) } }), header: AnyView(HStack { URLimageView(urlString: self.mImg) VStack(alignment: .leading) { Text(self.mName) Text(self.mDate) .font(.system(size: 10)) .foregroundColor(Color.gray) }}), isPresented: $showingHalfModal) } } } .tabItem { Image(systemName: "flame") Text("Launches") } // Text("rockets") ZStack { NavigationView { VStack { Spacer() .frame(height: 1) .navigationBarTitle("Rockets") List { ForEach(rockets, id: \.id) { rocket in Button(action: { withAnimation { self.showingHalfModal2 = true } }) { HStack { Group { Text(rocket.name) .font(.system(size: 23)) .frame(maxWidth: .infinity, alignment: .leading) .fixedSize(horizontal: false, vertical: true) Text("Active: " + String(rocket.active)) .font(.system(size: 15)) .foregroundColor(Color.gray) Spacer() } } } .buttonStyle(PlainButtonStyle()) } } }.onAppear { rocketApiCall().getUsers{ (rockets) in rockets = rockets} }.listStyle(SidebarListStyle()) .frame(alignment: .center) } } if showingHalfModal2 { HalfModalView(content: AnyView(HStack { VStack { Text("oogabooga smelly") .padding() } }), header: AnyView(HStack { VStack(alignment: .leading) { Text("you") Text("smell") .font(.system(size: 10)) .foregroundColor(Color.gray) }}), isPresented: $showingHalfModal2) } .tabItem { Image(systemName: "paperplane") Text("Rockets") } Text("launchpads") .tabItem { Image(systemName: "arrow.up") Text("Launchpads") } Text("landpads") .tabItem { Image(systemName: "arrow.down") Text("Landpads") } Text("crew") .tabItem { Image(systemName: "person.3") Text("Crew") } Text("roadster") .tabItem { Image(systemName: "car") Text("Roadster") } // Text("about") aboutPage .tabItem { Image(systemName: "questionmark") Text("About app") } } var aboutPage: some View { VStack { Text("SpaceX") Text("Version: \(Bundle.main.appVersionShort!) (\(Bundle.main.appVersionLong!))") .frame(maxWidth: .infinity) Text("© Charlie Kingsland, 2020") } } // var rocketListButtons: some View { // // } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } extension Date { func getFormattedDate(format: String) -> String { let dateformat = DateFormatter() dateformat.dateFormat = format return dateformat.string(from: self) } } extension Bundle { public var appVersionShort: String? { if let result = infoDictionary?["CFBundleShortVersionString"] as? String { return result } else { return "⚠️" } } public var appVersionLong: String? { if let result = infoDictionary?["CFBundleVersion"] as? String { return result } else { return "⚠️" } } public var appName: String? { if let result = infoDictionary?["CFBundleName"] as? String { return result } else { return "⚠️" } } } ```