comparison Simoleon/Helpers/CurrencyRow.swift @ 21:c3dda63f50ed v1.1

Added Core Data and UI changes - Implement Watchlist - Change conversion design - Improve UX
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Mon, 19 Jul 2021 19:27:12 +0100
parents 94fd7ac93060
children c52966834f83
comparison
equal deleted inserted replaced
20:f8aabe5b7251 21:c3dda63f50ed
6 // 6 //
7 7
8 import SwiftUI 8 import SwiftUI
9 9
10 struct CurrencyRow: View { 10 struct CurrencyRow: View {
11 var currency: String 11 var currencyPair: String
12 let currencyMetadata: [String: CurrencyMetadataModel] = parseJson("CurrencyMetadata.json") 12 let currencyMetadata: [String: CurrencyMetadataModel] = parseJson("CurrencyMetadata.json")
13 13
14 var body: some View { 14 var body: some View {
15 HStack { 15 HStack {
16 Image(currencyMetadata[currency]!.flag) 16 let currencies = currencyPair.split(separator: "/")
17 Image(currencyMetadata[String(currencies[0])]!.flag)
17 .resizable() 18 .resizable()
18 .aspectRatio(contentMode: .fill) 19 .aspectRatio(contentMode: .fill)
19 .frame(width: 30, height: 30) 20 .frame(width: 30, height: 30)
20 .clipShape(Circle()) 21 .clipShape(Circle())
21 .overlay(Circle().stroke(Color(.systemGray), lineWidth: 1)) 22 .overlay(Circle().stroke(Color(.systemGray), lineWidth: 1))
22 23
23 VStack(alignment: .leading) { 24 Image(currencyMetadata[String(currencies[1])]!.flag)
24 Text("\(currency)") 25 .resizable()
25 .fontWeight(.semibold) 26 .aspectRatio(contentMode: .fill)
26 .foregroundColor(Color("PlainButton")) 27 .frame(width: 30, height: 30)
27 28 .clipShape(Circle())
28 Text("\(currencyMetadata[currency]!.name)") 29 .overlay(Circle().stroke(Color(.systemGray), lineWidth: 1))
29 .font(.footnote) 30 .offset(x: -20)
30 .fontWeight(.semibold) 31 .padding(.trailing, -20)
31 .foregroundColor(Color("PlainButton")) 32
32 .opacity(0.5) 33 Text("From \(String(currencies[0])) to \(String(currencies[1]))")
33 .lineLimit(1) 34 .fontWeight(.semibold)
34 } 35 .foregroundColor(Color("PlainButton"))
35 .padding(.horizontal) 36 .padding(.leading)
37
38 Spacer()
36 } 39 }
37 } 40 }
38 } 41 }
39 42
40 struct CurrencyRow_Previews: PreviewProvider { 43 struct CurrencyRow_Previews: PreviewProvider {
41 static var previews: some View { 44 static var previews: some View {
42 CurrencyRow(currency: "USD") 45 CurrencyRow(currencyPair: "USD/GBP")
43 } 46 }
44 } 47 }