Guest User

Untitled

a guest
Nov 12th, 2022
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.29 KB | Source Code | 0 0
  1. import SwiftUI
  2.  
  3. struct ContentView: View {
  4.    
  5.     let astronauts: [String: Astronaut] = Bundle.main.decode("astronauts.json")
  6.     let missions: [Mission] = Bundle.main.decode("missions.json")
  7.    
  8.     let columns = [
  9.         GridItem(.adaptive(minimum: 150))
  10.     ]
  11.    
  12.     var body: some View {
  13.         NavigationView {
  14.             ScrollView {
  15.                 LazyVGrid(columns: columns) {
  16.                     ForEach(missions) { mission in
  17.                         NavigationLink {
  18.                             Text("Detail View")
  19.                         } label:  {
  20.                             VStack {
  21.                                 Image(mission.image)
  22.                                     .resizable()
  23.                                     .scaledToFit()
  24.                                     .frame(width: 100, height: 100)
  25.                                     .padding()
  26.                                    
  27.                                 VStack {
  28.                                     Text(mission.displayName)
  29.                                         .font(.headline)
  30.                                         .foregroundColor(.white)
  31.                                    
  32.                                     Text(mission.formattedLaunchDate)
  33.                                         .font(.caption)
  34.                                         .foregroundColor(.white.opacity(0.5))
  35.                                        
  36.                                 }
  37.                                 .padding(.vertical)
  38.                                 .frame(maxWidth: .infinity)
  39.                                 .background(.lightBackground)
  40.                             }
  41.                             .clipShape(RoundedRectangle(cornerRadius: 10))
  42.                             .overlay(
  43.                                 RoundedRectangle(cornerRadius: 10)
  44.                                     .stroke(.lightBackground))
  45.                         }
  46.                     }
  47.                 }
  48.                 .padding([.horizontal, .bottom])
  49.             }
  50.             .navigationTitle("Moonshot")
  51.             .background(.darkBackground)
  52.             .preferredColorScheme(.dark)
  53.         }
  54.     }
  55. }
  56.  
  57. struct ContentView_Previews: PreviewProvider {
  58.     static var previews: some View {
  59.         ContentView()
  60.     }
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment