diff LazyBear/Views/Home/Helpers/StockSheetRow.swift @ 424:6dd97877f575

Improve code, reorganize files
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sun, 13 Jun 2021 19:40:42 +0200
parents
children 4effac4733b0
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Home/Helpers/StockSheetRow.swift	Sun Jun 13 19:40:42 2021 +0200
@@ -0,0 +1,60 @@
+//
+//  StockSheetRow.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 13/6/21.
+//
+
+import SwiftUI
+import StockCharts
+
+struct StockSheetRow: View {
+    var symbol: String
+    var company: QuoteModel
+    var intradayPrices: [Double]?
+    
+    var body: some View {
+        HStack {
+            VStack(alignment: .leading) {
+                Text(symbol.capitalized.capitalized)
+                    .fontWeight(.semibold)
+                
+                Text(company.companyName.capitalized)
+                    .font(.callout)
+                    .fontWeight(.semibold)
+                    .opacity(0.6)
+                    .lineLimit(1)
+            }
+            
+            Spacer()
+            if let prices = intradayPrices {
+                LineChartView(data: prices, dates: nil, hours: nil, dragGesture: false)
+                    .frame(width: 80)
+                    .padding(.vertical, 10)
+                    .padding(.leading)
+            }
+            
+            if let latestPrice = company.latestPrice, let changePercent = company.changePercent {
+                VStack(alignment: .trailing) {
+                    Text("\(latestPrice, specifier: "%.2f")")
+                        .foregroundColor(changePercent < 0 ? .red: .green)
+                        .fontWeight(.semibold)
+
+                    Text("\(changePercent * 100, specifier: "%.2f")%")
+                        .foregroundColor(changePercent < 0 ? .red: .green)
+                        .font(.callout)
+                        .fontWeight(.semibold)
+                }
+            }
+        }
+    }
+}
+
+struct StockSheetRow_Previews: PreviewProvider {
+    static var previews: some View {
+        StockSheetRow(
+            symbol: "aapl",
+            company: QuoteModel(changePercent: 0.03, companyName: "Apple Inc", latestPrice: 120.3)
+        )
+    }
+}