Mercurial > public > simoleon
comparison Simoleon/Helpers/CurrencyRow.swift @ 11:a62e5e4a4f02
Implementing networking
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Tue, 13 Jul 2021 12:14:42 +0100 |
parents | ed35ef4738b9 |
children | cdc5f728b105 |
comparison
equal
deleted
inserted
replaced
10:ed35ef4738b9 | 11:a62e5e4a4f02 |
---|---|
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 struct CurrencyRow: View { | 10 struct CurrencyRow: View { |
11 var currencyQuote: CurrencyQuoteModel | 11 var currencyQuote: CurrencyQuoteModel |
12 let currencies: [String: CurrencyModel] = parseJson("Currencies.json") | 12 let currenciesMetadata: [String: CurrencyMetadataModel] = parseJson("CurrencyMetadata.json") |
13 | 13 |
14 var body: some View { | 14 var body: some View { |
15 VStack { | 15 VStack(alignment: .leading) { |
16 RoundedRectangle(cornerRadius: 10) | 16 RoundedRectangle(cornerRadius: 10) |
17 .rectangleModifier(Color("Bone"), 100) | 17 .rectangleModifier(Color("Shadow"), 100) |
18 | 18 |
19 RoundedRectangle(cornerRadius: 10) | 19 RoundedRectangle(cornerRadius: 10) |
20 .rectangleModifier(Color(.systemBackground), 100) | 20 .rectangleModifier(Color(.systemBackground), 100) |
21 .overlay( | 21 .overlay( |
22 HStack { | 22 HStack { |
23 let symbols = currencyQuote.symbol.split(separator: "/") | 23 let symbols = currencyQuote.symbol!.split(separator: "/") |
24 let mainCurrencyFlag = currencies[String(symbols[0])]!.flag | 24 let mainCurrencyFlag = currenciesMetadata[String(symbols[0])]!.flag |
25 let secondaryCurrencyFlag = currencies[String(symbols[1])]!.flag | 25 let secondaryCurrencyFlag = currenciesMetadata[String(symbols[1])]!.flag |
26 | 26 |
27 SmallFlagsPair(mainCurrencyFlag: mainCurrencyFlag, secondaryCurrencyFlag: secondaryCurrencyFlag) | 27 FlagPair(mainCurrencyFlag: mainCurrencyFlag, secondaryCurrencyFlag: secondaryCurrencyFlag) |
28 | 28 |
29 VStack(alignment: .leading) { | 29 VStack(alignment: .leading) { |
30 Text("\(String(symbols[0]))") | 30 Text("\(String(symbols[0]))") |
31 .fontWeight(.semibold) | 31 .fontWeight(.semibold) |
32 | 32 |
35 } | 35 } |
36 .padding(.horizontal) | 36 .padding(.horizontal) |
37 | 37 |
38 VStack(alignment: .leading) { | 38 VStack(alignment: .leading) { |
39 Text("Bid") | 39 Text("Bid") |
40 Text("\(currencyQuote.bid, specifier: "%.4f")") | 40 Text("\(currencyQuote.bid!, specifier: "%.4f")") |
41 .fontWeight(.semibold) | 41 .fontWeight(.semibold) |
42 | 42 |
43 } | 43 } |
44 .padding(.trailing) | 44 .padding(.trailing) |
45 | 45 |
46 VStack(alignment: .leading) { | 46 VStack(alignment: .leading) { |
47 Text("Ask") | 47 Text("Ask") |
48 Text("\(currencyQuote.ask, specifier: "%.4f")") | 48 Text("\(currencyQuote.ask!, specifier: "%.4f")") |
49 .fontWeight(.semibold) | 49 .fontWeight(.semibold) |
50 | 50 |
51 } | 51 } |
52 | |
53 Spacer() | |
52 } | 54 } |
55 .padding(.horizontal) | |
53 ) | 56 ) |
54 .offset(x: -10.0, y: -120.0) | 57 .offset(x: -10.0, y: -120.0) |
55 .padding(.bottom, -120) | 58 .padding(.bottom, -120) |
56 } | 59 } |
57 .padding(.leading, 10) | 60 .padding(.leading, 10) |
58 .padding(.horizontal) | 61 .padding(.horizontal) |
62 } | |
63 } | |
64 extension RoundedRectangle { | |
65 func rectangleModifier(_ colour: Color, _ height: CGFloat) -> some View { | |
66 self | |
67 .strokeBorder(Color("Border"), lineWidth: 2) | |
68 .background(RoundedRectangle(cornerRadius: 10).foregroundColor(colour)) | |
69 .frame(height: height) | |
70 | |
59 } | 71 } |
60 } | 72 } |
61 | 73 |
62 struct CurrencyRow_Previews: PreviewProvider { | 74 struct CurrencyRow_Previews: PreviewProvider { |
63 static var previews: some View { | 75 static var previews: some View { |