11
|
1 //
|
|
2 // BuyPremiumModalView.swift
|
|
3 // GeoQuiz
|
|
4 //
|
|
5 // Created by Dennis Concepción Martín on 9/10/22.
|
|
6 //
|
|
7
|
|
8 import SwiftUI
|
|
9
|
|
10 struct BuyPremiumModalView: View {
|
26
|
11 @ObservedObject var storeController: StoreController
|
19
|
12
|
11
|
13 @Environment(\.dismiss) var dismiss
|
|
14
|
|
15 var body: some View {
|
19
|
16 NavigationStack {
|
13
|
17 ZStack {
|
|
18 ScrollView(showsIndicators: false) {
|
|
19 VStack(alignment: .center, spacing: 20) {
|
|
20 VStack(spacing: 20) {
|
|
21 Text("Unlock all games 🤩")
|
|
22 .font(.largeTitle.bold())
|
|
23
|
|
24 Text("Unlock three more game modes to become a geography master and support the future development of GeoQuiz.")
|
|
25 .foregroundColor(.secondary)
|
|
26 .multilineTextAlignment(.center)
|
|
27 .frame(maxWidth: 400)
|
|
28 }
|
|
29 .padding()
|
|
30
|
|
31 ScrollView(.horizontal, showsIndicators: false) {
|
|
32 HStack(spacing: 20) {
|
|
33 Group {
|
|
34 Image("GuessTheCapital")
|
|
35 .resizable()
|
|
36
|
|
37 Image("GuessTheCountry")
|
|
38 .resizable()
|
|
39
|
|
40 Image("GuessThePopulation")
|
|
41 .resizable()
|
|
42 }
|
|
43 .scaledToFit()
|
|
44 .cornerRadius(25)
|
|
45 .frame(height: 500)
|
|
46 }
|
|
47 .padding()
|
|
48 }
|
11
|
49
|
13
|
50 VStack(spacing: 10) {
|
|
51 Text("A one-time payment.")
|
|
52 .font(.title)
|
|
53 .fontWeight(.semibold)
|
|
54
|
|
55 Text("No subscriptions.")
|
|
56 .font(.title2)
|
|
57 .fontWeight(.semibold)
|
|
58 .foregroundColor(.secondary)
|
|
59
|
|
60 VStack {
|
26
|
61 if let package = storeController.offerings?.current?.lifetime {
|
13
|
62 Button {
|
26
|
63 storeController.buy(package)
|
13
|
64 } label: {
|
|
65 Text("Buy for \(package.storeProduct.localizedPriceString)")
|
|
66 .font(.headline)
|
|
67 .padding()
|
|
68 }
|
|
69 .buttonStyle(.borderedProminent)
|
|
70 .padding(.top)
|
|
71 } else {
|
|
72 ProgressView()
|
|
73 }
|
11
|
74 }
|
13
|
75
|
26
|
76 Button("Restore purchases", action: storeController.restorePurchase)
|
11
|
77 }
|
|
78 .padding()
|
13
|
79
|
|
80 VStack {
|
|
81 Text("GeoQuiz is an indie game")
|
|
82 Text("I appreciate your support ❤️")
|
|
83 }
|
|
84 .font(.callout)
|
|
85 .foregroundColor(.secondary)
|
|
86 .padding()
|
11
|
87 }
|
13
|
88 }
|
|
89
|
26
|
90 if storeController.showingActivityAlert {
|
13
|
91 ActivityAlert()
|
11
|
92 }
|
|
93 }
|
|
94 .navigationBarTitleDisplayMode(.inline)
|
26
|
95 .onAppear(perform: storeController.fetchOfferings)
|
11
|
96 .toolbar {
|
|
97 ToolbarItem(placement: .cancellationAction) {
|
|
98 Button {
|
|
99 dismiss()
|
|
100 } label: {
|
|
101 Label("Exit", systemImage: "multiply")
|
|
102 }
|
|
103 }
|
|
104 }
|
13
|
105 }
|
26
|
106 .disabled(storeController.showingActivityAlert)
|
|
107 .interactiveDismissDisabled(storeController.showingActivityAlert)
|
13
|
108
|
26
|
109 .alert(storeController.errorAlertTitle, isPresented: $storeController.showingErrorAlert) {
|
13
|
110 Button("OK", role: .cancel) { }
|
|
111 } message: {
|
26
|
112 Text(storeController.errorAlertMessage)
|
13
|
113 }
|
|
114
|
26
|
115 .alert("GeoQuiz Premium is active!", isPresented: $storeController.showingSuccessAlert) {
|
13
|
116 Button("OK", role: .cancel) { dismiss() }
|
|
117 } message: {
|
|
118 Text("Thanks for supporting indie apps ❤️")
|
11
|
119 }
|
|
120 }
|
|
121 }
|
|
122
|
|
123 struct BuyPremiumModalView_Previews: PreviewProvider {
|
|
124 static var previews: some View {
|
26
|
125 BuyPremiumModalView(storeController: StoreController())
|
11
|
126 }
|
|
127 }
|