comparison GeoQuiz/GuessTheCapitalView.swift @ 10:a793f33f05fb

refactor code and fix layout
author Dennis C. M. <dennis@denniscm.com>
date Sat, 08 Oct 2022 21:36:40 +0200
parents e09959b4e4a8
children f1967f8cc67b
comparison
equal deleted inserted replaced
9:3540c7efc216 10:a793f33f05fb
14 ZStack { 14 ZStack {
15 LinearGradient(gradient: .secondary, startPoint: .top, endPoint: .bottom) 15 LinearGradient(gradient: .secondary, startPoint: .top, endPoint: .bottom)
16 .ignoresSafeArea() 16 .ignoresSafeArea()
17 17
18 GeometryReader { geo in 18 GeometryReader { geo in
19 VStack(spacing: 20) { 19 VStack {
20 GameToolbar(game: game, color: .atomicTangerine) 20 GameToolbar(game: game, color: .atomicTangerine)
21 21
22 Spacer() 22 Spacer()
23 23
24 FlagImage(flagSymbol: game.correctAnswer.value.flag, cornerRadius: 20) 24 FlagImage(flagSymbol: game.correctAnswer.value.flag, cornerRadius: 20)
25 .clipShape(RoundedRectangle(cornerRadius: 20))
25 .shadow(radius: 10) 26 .shadow(radius: 10)
26 .frame(height: geo.size.height * 0.15) 27 .frame(height: geo.size.height * 0.15)
27 28
28 Spacer() 29 Spacer()
29 30
30 HStack { 31 VStack(alignment: .leading) {
31 VStack(alignment: .leading, spacing: 10) { 32 VStack(alignment: .leading, spacing: 10) {
32 Text("Question \(game.questionCounter) of \(game.data.count)") 33 Text("Question \(game.questionCounter) of \(game.data.count)")
33 .font(.title3) 34 .font(.title3)
34 .foregroundColor(.white.opacity(0.7)) 35 .foregroundColor(.white.opacity(0.7))
35 36
37 .font(.title) 38 .font(.title)
38 .fontWeight(.semibold) 39 .fontWeight(.semibold)
39 .foregroundColor(.white) 40 .foregroundColor(.white)
40 } 41 }
41 42
42 Spacer() 43 VStack(spacing: 15) {
43 } 44 ForEach(Array(game.userChoices.keys), id: \.self) { countryName in
44 45 Button {
45 VStack { 46 game.answer((key: countryName, value: game.data[countryName]!)) {
46 ForEach(Array(game.userChoices.keys), id: \.self) { countryName in 47 game.selector()
47 Button { 48 }
48 game.answer((key: countryName, value: game.data[countryName]!)) { 49 } label: {
49 game.selector() 50 AnswerButton(
51 optionName: game.data[countryName]!.capital,
52 color: .chinaPink
53 )
54 .frame(height: geo.size.height * 0.08)
50 } 55 }
51 } label: {
52 AnswerButton(
53 optionName: game.data[countryName]!.capital,
54 color: .chinaPink
55 )
56 .frame(height: geo.size.height * 0.08)
57 } 56 }
58 } 57 }
59 } 58 }
59 .frame(maxWidth: 500)
60 } 60 }
61 .padding() 61 .padding()
62 } 62 }
63 } 63 }
64 .navigationBarHidden(true) 64 .navigationBarHidden(true)
65 .modifier(GameAlertsModifier(game: game)) 65 .modifier(GameAlertsModifier(game: game))
66 } 66 }
67 } 67 }
68 68
69 struct GuessCapitalView_Previews: PreviewProvider { 69 struct GuessTheCapitalView_Previews: PreviewProvider {
70 static var previews: some View { 70 static var previews: some View {
71 NavigationView { 71 GuessTheCapitalView()
72 GuessTheCapitalView() 72 .previewDevice(PreviewDevice(rawValue: "iPhone 14 Pro Max"))
73 } 73 .previewDisplayName("iPhone 14 Pro Max")
74
75 GuessTheCapitalView()
76 .previewDevice(PreviewDevice(rawValue: "iPad Pro (12.9-inch) (5th generation)"))
77 .previewDisplayName("iPad Pro (12.9-inch) (5th generation)")
74 } 78 }
75 } 79 }