Mercurial > public > simoleon
comparison Simoleon/Helpers/CurrencySelector.swift @ 183:d2398f02e1ce
implement unit currency selector
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Mon, 20 Dec 2021 12:28:16 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
182:ba3ebe8cefe5 | 183:d2398f02e1ce |
---|---|
1 // | |
2 // CurrencySelector.swift | |
3 // Simoleon | |
4 // | |
5 // Created by Dennis Concepción Martín on 8/12/21. | |
6 // | |
7 | |
8 import SwiftUI | |
9 | |
10 enum Selection { | |
11 case baseCurrency, quoteCurrency | |
12 } | |
13 | |
14 struct CurrencySelector: View { | |
15 @State private var baseCurrency = SupportedCurrencyResult(code: "EUR", name: "Euro", isCrypto: 0) | |
16 @State private var quoteCurrency = SupportedCurrencyResult(code: "CHF", name: "Swiss Franc", isCrypto: 0) | |
17 @State private var showingCurrencyList = false | |
18 @State private var selecting: Selection = .baseCurrency | |
19 | |
20 var body: some View { | |
21 HStack { | |
22 Button(action: { | |
23 selecting = .baseCurrency | |
24 showingCurrencyList.toggle() | |
25 | |
26 }) { | |
27 RoundedRectangle(cornerRadius: 15) | |
28 .foregroundColor(Color(.secondarySystemBackground)) | |
29 .frame(height: 60) | |
30 .overlay( | |
31 Text(baseCurrency.code) | |
32 ) | |
33 } | |
34 | |
35 Button(action: { | |
36 selecting = .quoteCurrency | |
37 showingCurrencyList.toggle() | |
38 }) { | |
39 RoundedRectangle(cornerRadius: 15) | |
40 .foregroundColor(Color(.secondarySystemBackground)) | |
41 .frame(height: 60) | |
42 .overlay( | |
43 Text(quoteCurrency.code) | |
44 ) | |
45 } | |
46 } | |
47 .sheet(isPresented: $showingCurrencyList) { | |
48 CurrencyList(baseCurrency: $baseCurrency, quoteCurrency: $quoteCurrency, selecting: selecting) | |
49 } | |
50 } | |
51 } | |
52 | |
53 struct CurrencySelector_Previews: PreviewProvider { | |
54 static var previews: some View { | |
55 CurrencySelector() | |
56 } | |
57 } |