Mercurial > public > geoquiz
annotate GeoQuiz/ContentView.swift @ 13:bdfff35dd43c
implement RevenueCat
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Wed, 12 Oct 2022 11:47:29 +0200 |
parents | 039b26a99a48 |
children | 136928bae534 |
rev | line source |
---|---|
0 | 1 // |
2 // ContentView.swift | |
3 // GeoQuiz | |
4 // | |
5 // Created by Dennis Concepción Martín on 5/9/22. | |
6 // | |
7 | |
8 import SwiftUI | |
9 | |
10 struct ContentView: View { | |
13 | 11 @State private var gameModeSelection: GameMode? = nil |
12 | |
7 | 13 @State private var showingBuyPremiumModalView = false |
5 | 14 @State private var showingSettingsModalView = false |
11 | 15 @State private var showingProfileModalView = false |
0 | 16 |
13 | 17 @StateObject var storeKitRC = StoreKitRC() |
18 | |
0 | 19 var body: some View { |
20 NavigationView { | |
13 | 21 VStack { |
22 NavigationLink( | |
23 destination: GuessTheFlagView(), | |
24 tag: GameMode.guessTheFlag, | |
25 selection: $gameModeSelection) | |
26 { | |
27 EmptyView() | |
28 } | |
29 | |
30 NavigationLink( | |
31 destination: GuessTheCapitalView(), | |
32 tag: GameMode.guessTheCapital, | |
33 selection: $gameModeSelection) | |
34 { | |
35 EmptyView() | |
36 } | |
37 | |
38 NavigationLink( | |
39 destination: GuessTheCountryView(), | |
40 tag: GameMode.guessTheCountry, | |
41 selection: $gameModeSelection) | |
42 { | |
43 EmptyView() | |
44 } | |
45 | |
46 NavigationLink( | |
47 destination: GuessThePopulationView(), | |
48 tag: GameMode.guessThePopulation, | |
49 selection: $gameModeSelection) | |
50 { | |
51 EmptyView() | |
52 } | |
53 | |
54 ScrollView(showsIndicators: false) { | |
55 VStack(alignment: .leading, spacing: 30) { | |
56 Text("Select a game 🎮") | |
57 .font(.largeTitle.bold()) | |
58 .padding(.bottom) | |
59 | |
60 Button { | |
61 gameModeSelection = .guessTheFlag | |
62 } label: { | |
63 GameButton( | |
64 gradient: .main, | |
65 level: "Level 1", | |
66 symbol: "flag.fill", | |
67 name: "Guess the flag" | |
68 ) | |
69 } | |
70 | |
71 Button { | |
72 if storeKitRC.isActive { | |
73 gameModeSelection = .guessTheCapital | |
74 } else { | |
75 showingBuyPremiumModalView = true | |
76 } | |
77 } label: { | |
78 GameButton( | |
79 gradient: .secondary, | |
80 level: "Level 2", | |
81 symbol: storeKitRC.isActive ? "building.2.fill": "lock.fill", | |
82 name: "Guess the capital" | |
83 ) | |
84 } | |
85 | |
86 Button { | |
87 if storeKitRC.isActive { | |
88 gameModeSelection = .guessTheCountry | |
89 } else { | |
90 showingBuyPremiumModalView = true | |
91 } | |
92 } label: { | |
93 GameButton( | |
94 gradient: .tertiary, | |
95 level: "Level 3", | |
96 symbol: storeKitRC.isActive ? "globe.americas.fill": "lock.fill", | |
97 name: "Guess the country" | |
98 ) | |
99 } | |
100 | |
101 Button { | |
102 if storeKitRC.isActive { | |
103 gameModeSelection = .guessThePopulation | |
104 } else { | |
105 showingBuyPremiumModalView = true | |
106 } | |
107 } label: { | |
108 GameButton( | |
109 gradient: .quaternary, | |
110 level: "Level 4", | |
111 symbol: storeKitRC.isActive ? "person.fill": "lock.fill", | |
112 name: "Guess the population" | |
113 ) | |
114 } | |
0 | 115 } |
13 | 116 .padding() |
0 | 117 } |
118 } | |
10
a793f33f05fb
refactor code and fix layout
Dennis C. M. <dennis@denniscm.com>
parents:
8
diff
changeset
|
119 .navigationTitle("GeoQuiz") |
a793f33f05fb
refactor code and fix layout
Dennis C. M. <dennis@denniscm.com>
parents:
8
diff
changeset
|
120 .navigationBarTitleDisplayMode(.inline) |
0 | 121 .toolbar { |
5 | 122 ToolbarItem(placement: .navigationBarLeading) { |
123 Button { | |
124 showingSettingsModalView = true | |
125 } label: { | |
126 Label("Settings", systemImage: "gear") | |
127 } | |
128 } | |
129 | |
130 ToolbarItemGroup { | |
13 | 131 if !storeKitRC.isActive { |
132 Button { | |
133 showingBuyPremiumModalView = true | |
134 } label: { | |
135 Label("Buy premium", systemImage: "star") | |
136 } | |
5 | 137 } |
11 | 138 |
139 Button { | |
140 showingProfileModalView = true | |
141 } label: { | |
142 Label("Profile", systemImage: "person") | |
143 } | |
0 | 144 } |
145 } | |
7 | 146 .sheet(isPresented: $showingBuyPremiumModalView) { |
13 | 147 BuyPremiumModalView(storeKitRC: storeKitRC) |
0 | 148 } |
5 | 149 |
150 .sheet(isPresented: $showingSettingsModalView) { | |
151 SettingsModalView() | |
152 } | |
11 | 153 |
154 .sheet(isPresented: $showingProfileModalView) { | |
155 ProfileModalView() | |
156 } | |
0 | 157 } |
6 | 158 .navigationViewStyle(StackNavigationViewStyle()) |
0 | 159 } |
160 } | |
161 | |
162 struct ContentView_Previews: PreviewProvider { | |
163 static var previews: some View { | |
164 ContentView() | |
165 } | |
166 } |