Mercurial > public > lazybear
comparison 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 |
comparison
equal
deleted
inserted
replaced
423:bdfdf3a1b34e | 424:6dd97877f575 |
---|---|
1 // | |
2 // StockSheetRow.swift | |
3 // LazyBear | |
4 // | |
5 // Created by Dennis Concepción Martín on 13/6/21. | |
6 // | |
7 | |
8 import SwiftUI | |
9 import StockCharts | |
10 | |
11 struct StockSheetRow: View { | |
12 var symbol: String | |
13 var company: QuoteModel | |
14 var intradayPrices: [Double]? | |
15 | |
16 var body: some View { | |
17 HStack { | |
18 VStack(alignment: .leading) { | |
19 Text(symbol.capitalized.capitalized) | |
20 .fontWeight(.semibold) | |
21 | |
22 Text(company.companyName.capitalized) | |
23 .font(.callout) | |
24 .fontWeight(.semibold) | |
25 .opacity(0.6) | |
26 .lineLimit(1) | |
27 } | |
28 | |
29 Spacer() | |
30 if let prices = intradayPrices { | |
31 LineChartView(data: prices, dates: nil, hours: nil, dragGesture: false) | |
32 .frame(width: 80) | |
33 .padding(.vertical, 10) | |
34 .padding(.leading) | |
35 } | |
36 | |
37 if let latestPrice = company.latestPrice, let changePercent = company.changePercent { | |
38 VStack(alignment: .trailing) { | |
39 Text("\(latestPrice, specifier: "%.2f")") | |
40 .foregroundColor(changePercent < 0 ? .red: .green) | |
41 .fontWeight(.semibold) | |
42 | |
43 Text("\(changePercent * 100, specifier: "%.2f")%") | |
44 .foregroundColor(changePercent < 0 ? .red: .green) | |
45 .font(.callout) | |
46 .fontWeight(.semibold) | |
47 } | |
48 } | |
49 } | |
50 } | |
51 } | |
52 | |
53 struct StockSheetRow_Previews: PreviewProvider { | |
54 static var previews: some View { | |
55 StockSheetRow( | |
56 symbol: "aapl", | |
57 company: QuoteModel(changePercent: 0.03, companyName: "Apple Inc", latestPrice: 120.3) | |
58 ) | |
59 } | |
60 } |