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