diff Simoleon/UI/CurrencyButton.swift @ 156:84137052813d

Refactor code
author Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com>
date Sat, 28 Aug 2021 11:15:25 +0100
parents
children 0c589138a6f3
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Simoleon/UI/CurrencyButton.swift	Sat Aug 28 11:15:25 2021 +0100
@@ -0,0 +1,34 @@
+//
+//  CurrencyButton.swift
+//  Simoleon
+//
+//  Created by Dennis Concepción Martín on 24/8/21.
+//
+
+import SwiftUI
+
+struct CurrencyButton: View {
+    var selectedCurrency: String
+    let currencyDetails: [String: CurrencyModel] = try! read(json: "Currencies.json")
+    
+    var body: some View {
+        let currency = currencyDetails[selectedCurrency]!
+        RoundedRectangle(cornerRadius: 15)
+            .foregroundColor(Color(.secondarySystemBackground))
+            .frame(height: 60)
+            .overlay(
+                HStack {
+                    Flag(flag: currency.flag)
+                    Text(currency.symbol)
+                        .foregroundColor(.primary)
+                        .font(.headline)
+                }
+            )
+    }
+}
+
+struct CurrencyButton_Previews: PreviewProvider {
+    static var previews: some View {
+        CurrencyButton(selectedCurrency: "USD")
+    }
+}