Mercurial > public > simoleon
diff Simoleon/Helpers/CurrencySelector.swift @ 28:4f862c618b44
Implemented RevenueCat
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Thu, 22 Jul 2021 19:06:01 +0100 |
parents | c3dda63f50ed |
children | c52966834f83 |
line wrap: on
line diff
--- a/Simoleon/Helpers/CurrencySelector.swift Wed Jul 21 12:36:10 2021 +0100 +++ b/Simoleon/Helpers/CurrencySelector.swift Thu Jul 22 19:06:01 2021 +0100 @@ -6,12 +6,16 @@ // import SwiftUI +import Purchases struct CurrencySelector: View { @Binding var currencyPair: String @Binding var showingCurrencySelector: Bool + @EnvironmentObject var subscriptionController: SubscriptionController + @State private var searchCurrency = "" @State private var searching = false + @State private var showingSubscriptionPaywall = false var body: some View { NavigationView { @@ -30,10 +34,7 @@ Section(header: Text("All currencies")) { ForEach(currencyPairs(), id: \.self) { currencyPair in - Button(action: { - self.currencyPair = currencyPair - showingCurrencySelector = false - }) { + Button(action: { select(currencyPair) }) { CurrencyRow(currencyPair: currencyPair) } } @@ -41,19 +42,20 @@ } .gesture(DragGesture() .onChanged({ _ in - UIApplication.shared.dismissKeyboard() + UIApplication.shared.dismissKeyboard() + searching = false }) ) .navigationTitle("Currencies") .navigationBarTitleDisplayMode(.inline) .toolbar { - ToolbarItem(placement: .confirmationAction) { - Button("OK", action: { showingCurrencySelector = false }) + ToolbarItem(placement: .cancellationAction) { + Button("Cancel", action: { showingCurrencySelector = false }) } - ToolbarItem(placement: .cancellationAction) { + ToolbarItem(placement: .confirmationAction) { if searching { - Button("Cancel") { + Button("OK") { searchCurrency = "" withAnimation { searching = false @@ -64,6 +66,9 @@ } } } + .sheet(isPresented: $showingSubscriptionPaywall) { + Subscription(showingSubscriptionPaywall: $showingSubscriptionPaywall) + } } private func currencyPairs() -> [String] { @@ -75,11 +80,22 @@ return currencyPairs.filter { $0.contains(searchCurrency.uppercased()) } } } + + + private func select(_ currencyPair: String) { + if subscriptionController.isActive { + self.currencyPair = currencyPair + showingCurrencySelector = false + } else { + showingSubscriptionPaywall = true + } + } } struct CurrencySelector_Previews: PreviewProvider { static var previews: some View { CurrencySelector(currencyPair: .constant("USD/GBP"), showingCurrencySelector: .constant(false)) + .environmentObject(SubscriptionController()) } }