comparison GeoQuiz/BuyPremiumModalView.swift @ 19:f140bb277c96

refactor code
author Dennis C. M. <dennis@denniscm.com>
date Sun, 23 Oct 2022 00:11:38 +0100
parents bdfff35dd43c
children 425078c01194
comparison
equal deleted inserted replaced
18:d20cf93c9812 19:f140bb277c96
6 // 6 //
7 7
8 import SwiftUI 8 import SwiftUI
9 9
10 struct BuyPremiumModalView: View { 10 struct BuyPremiumModalView: View {
11 @ObservedObject var storeKitController: StoreKitController
12
11 @Environment(\.dismiss) var dismiss 13 @Environment(\.dismiss) var dismiss
12 @ObservedObject var storeKitRC: StoreKitRC
13 14
14 var body: some View { 15 var body: some View {
15 NavigationView { 16 NavigationStack {
16 ZStack { 17 ZStack {
17 ScrollView(showsIndicators: false) { 18 ScrollView(showsIndicators: false) {
18 VStack(alignment: .center, spacing: 20) { 19 VStack(alignment: .center, spacing: 20) {
19 VStack(spacing: 20) { 20 VStack(spacing: 20) {
20 Text("Unlock all games 🤩") 21 Text("Unlock all games 🤩")
55 .font(.title2) 56 .font(.title2)
56 .fontWeight(.semibold) 57 .fontWeight(.semibold)
57 .foregroundColor(.secondary) 58 .foregroundColor(.secondary)
58 59
59 VStack { 60 VStack {
60 if let package = storeKitRC.offerings?.current?.lifetime { 61 if let package = storeKitController.offerings?.current?.lifetime {
61 Button { 62 Button {
62 storeKitRC.buy(package) 63 storeKitController.buy(package)
63 } label: { 64 } label: {
64 Text("Buy for \(package.storeProduct.localizedPriceString)") 65 Text("Buy for \(package.storeProduct.localizedPriceString)")
65 .font(.headline) 66 .font(.headline)
66 .padding() 67 .padding()
67 } 68 }
70 } else { 71 } else {
71 ProgressView() 72 ProgressView()
72 } 73 }
73 } 74 }
74 75
75 Button("Restore purchases", action: storeKitRC.restorePurchase) 76 Button("Restore purchases", action: storeKitController.restorePurchase)
76 } 77 }
77 .padding() 78 .padding()
78 79
79 VStack { 80 VStack {
80 Text("GeoQuiz is an indie game") 81 Text("GeoQuiz is an indie game")
84 .foregroundColor(.secondary) 85 .foregroundColor(.secondary)
85 .padding() 86 .padding()
86 } 87 }
87 } 88 }
88 89
89 if storeKitRC.showingActivityAlert { 90 if storeKitController.showingActivityAlert {
90 ActivityAlert() 91 ActivityAlert()
91 } 92 }
92 } 93 }
93 .navigationBarTitleDisplayMode(.inline) 94 .navigationBarTitleDisplayMode(.inline)
94 .onAppear(perform: storeKitRC.fetchOfferings) 95 .onAppear(perform: storeKitController.fetchOfferings)
95 .toolbar { 96 .toolbar {
96 ToolbarItem(placement: .cancellationAction) { 97 ToolbarItem(placement: .cancellationAction) {
97 Button { 98 Button {
98 dismiss() 99 dismiss()
99 } label: { 100 } label: {
100 Label("Exit", systemImage: "multiply") 101 Label("Exit", systemImage: "multiply")
101 } 102 }
102 } 103 }
103 } 104 }
104 } 105 }
105 .disabled(storeKitRC.showingActivityAlert) 106 .disabled(storeKitController.showingActivityAlert)
106 .interactiveDismissDisabled(storeKitRC.showingActivityAlert) 107 .interactiveDismissDisabled(storeKitController.showingActivityAlert)
107 108
108 .alert(storeKitRC.errorAlertTitle, isPresented: $storeKitRC.showingErrorAlert) { 109 .alert(storeKitController.errorAlertTitle, isPresented: $storeKitController.showingErrorAlert) {
109 Button("OK", role: .cancel) { } 110 Button("OK", role: .cancel) { }
110 } message: { 111 } message: {
111 Text(storeKitRC.errorAlertMessage) 112 Text(storeKitController.errorAlertMessage)
112 } 113 }
113 114
114 .alert("GeoQuiz Premium is active!", isPresented: $storeKitRC.showingSuccessAlert) { 115 .alert("GeoQuiz Premium is active!", isPresented: $storeKitController.showingSuccessAlert) {
115 Button("OK", role: .cancel) { dismiss() } 116 Button("OK", role: .cancel) { dismiss() }
116 } message: { 117 } message: {
117 Text("Thanks for supporting indie apps ❤️") 118 Text("Thanks for supporting indie apps ❤️")
118 } 119 }
119 } 120 }
120 } 121 }
121 122
122 struct BuyPremiumModalView_Previews: PreviewProvider { 123 struct BuyPremiumModalView_Previews: PreviewProvider {
123 static var previews: some View { 124 static var previews: some View {
124 BuyPremiumModalView(storeKitRC: StoreKitRC()) 125 BuyPremiumModalView(storeKitController: StoreKitController())
125 } 126 }
126 } 127 }