comparison GeoQuiz/GuessTheCountryView.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: .tertiary, startPoint: .top, endPoint: .bottom) 15 LinearGradient(gradient: .tertiary, 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: .pinkLavender) 20 GameToolbar(game: game, color: .pinkLavender)
21 21
22 Spacer() 22 Spacer()
23 23
24 CityMap(game: game, geo: geo) 24 CityMap(game: game)
25 .frame(height: geo.size.height * 0.35)
25 26
26 Spacer() 27 Spacer()
27 28
28 HStack { 29 VStack(alignment: .leading) {
29 VStack(alignment: .leading, spacing: 10) { 30 VStack(alignment: .leading, spacing: 10) {
30 Text("Question \(game.questionCounter) of \(game.data.count)") 31 Text("Question \(game.questionCounter) of \(game.data.count)")
31 .font(.title3) 32 .font(.title3)
32 .foregroundColor(.white.opacity(0.7)) 33 .foregroundColor(.white.opacity(0.7))
33 34
35 .font(.title) 36 .font(.title)
36 .fontWeight(.semibold) 37 .fontWeight(.semibold)
37 .foregroundColor(.white) 38 .foregroundColor(.white)
38 } 39 }
39 40
40 Spacer() 41 VStack(spacing: 15) {
41 } 42 ForEach(Array(game.userChoices.keys), id: \.self) { cityName in
42 43 Button {
43 VStack { 44 game.answer((key: cityName, value: game.data[cityName]!)) {
44 ForEach(Array(game.userChoices.keys), id: \.self) { cityName in 45 game.selector()
45 Button { 46 }
46 game.answer((key: cityName, value: game.data[cityName]!)) { 47 } label: {
47 game.selector() 48 AnswerButton(
49 optionName: game.data[cityName]!.country,
50 color: .blueBell
51 )
52 .frame(height: geo.size.height * 0.08)
48 } 53 }
49 } label: {
50 AnswerButton(
51 optionName: game.data[cityName]!.country,
52 color: .blueBell
53 )
54 .frame(height: geo.size.height * 0.08)
55 } 54 }
56 } 55 }
57 } 56 }
58 57 .frame(maxWidth: 500)
59 } 58 }
60 .padding() 59 .padding()
61 } 60 }
62 } 61 }
63 .navigationBarHidden(true) 62 .navigationBarHidden(true)
66 } 65 }
67 66
68 struct GuessTheCountryView_Previews: PreviewProvider { 67 struct GuessTheCountryView_Previews: PreviewProvider {
69 static var previews: some View { 68 static var previews: some View {
70 GuessTheCountryView() 69 GuessTheCountryView()
70 .previewDevice(PreviewDevice(rawValue: "iPhone 14 Pro Max"))
71 .previewDisplayName("iPhone 14 Pro Max")
72
73 GuessTheCountryView()
74 .previewDevice(PreviewDevice(rawValue: "iPad Pro (12.9-inch) (5th generation)"))
75 .previewDisplayName("iPad Pro (12.9-inch) (5th generation)")
71 } 76 }
72 } 77 }