Mercurial > public > lazybear
comparison LazyBear/Views/Home/Helpers/StockItem.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 // StockItem.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 StockItem: View { | |
12 var symbol: String | |
13 var company: QuoteModel | |
14 var intradayPrices: [Double]? | |
15 | |
16 var body: some View { | |
17 RoundedRectangle(cornerRadius: 20) | |
18 .foregroundColor(Color(.secondarySystemBackground)) | |
19 .aspectRatio(0.8, contentMode: .fit) | |
20 .clipShape(RoundedRectangle(cornerRadius: 20)) | |
21 .overlay( | |
22 VStack(alignment: .leading) { | |
23 Group { | |
24 Text(symbol.uppercased()) | |
25 .fontWeight(.semibold) | |
26 .padding(.top) | |
27 | |
28 Text(company.companyName.capitalized) | |
29 .font(.callout) | |
30 .fontWeight(.semibold) | |
31 .opacity(0.6) | |
32 .lineLimit(1) | |
33 | |
34 if let latestPrice = company.latestPrice, let changePercent = company.changePercent { | |
35 VStack(alignment: .leading) { | |
36 Text("\(latestPrice, specifier: "%.2f")") | |
37 .foregroundColor(changePercent < 0 ? .red: .green) | |
38 .fontWeight(.semibold) | |
39 | |
40 Text("\(changePercent * 100, specifier: "%.2f")%") | |
41 .foregroundColor(changePercent < 0 ? .red: .green) | |
42 .font(.callout) | |
43 .fontWeight(.semibold) | |
44 } | |
45 .padding(.top) | |
46 } | |
47 } | |
48 .padding(.horizontal) | |
49 | |
50 Spacer() | |
51 | |
52 if let prices = intradayPrices { | |
53 LineChartView(data: prices, dates: nil, hours: nil, dragGesture: false) | |
54 .padding(.vertical) | |
55 .clipShape(RoundedRectangle(cornerRadius: 20)) | |
56 } | |
57 | |
58 } | |
59 ,alignment: .leading | |
60 ) | |
61 } | |
62 } | |
63 | |
64 struct StockItem_Previews: PreviewProvider { | |
65 static var previews: some View { | |
66 StockItem( | |
67 symbol: "aapl", | |
68 company: QuoteModel(changePercent: 0.03, companyName: "Apple Inc", latestPrice: 120.3) | |
69 ) | |
70 } | |
71 } |