Mercurial > public > lazybear
comparison LazyBear/Views/Home/Helpers/StockItem.swift @ 425:4effac4733b0
Changing keys from API responses
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Wed, 16 Jun 2021 13:46:01 +0200 |
parents | 6dd97877f575 |
children | 417148200aaf |
comparison
equal
deleted
inserted
replaced
424:6dd97877f575 | 425:4effac4733b0 |
---|---|
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 import StockCharts | 9 import StockCharts |
10 | 10 |
11 struct StockItem: View { | 11 struct StockItem: View { |
12 var symbol: String | 12 var company: CompanyModel |
13 var company: QuoteModel | |
14 var intradayPrices: [Double]? | |
15 | 13 |
16 var body: some View { | 14 var body: some View { |
17 RoundedRectangle(cornerRadius: 20) | 15 RoundedRectangle(cornerRadius: 20) |
18 .foregroundColor(Color(.secondarySystemBackground)) | 16 .foregroundColor(Color(.secondarySystemBackground)) |
19 .aspectRatio(0.8, contentMode: .fit) | 17 .aspectRatio(0.8, contentMode: .fit) |
20 .clipShape(RoundedRectangle(cornerRadius: 20)) | 18 .clipShape(RoundedRectangle(cornerRadius: 20)) |
21 .overlay( | 19 .overlay( |
22 VStack(alignment: .leading) { | 20 VStack(alignment: .leading) { |
23 Group { | 21 Group { |
24 Text(symbol.uppercased()) | 22 Text(company.symbol.uppercased()) |
25 .fontWeight(.semibold) | 23 .fontWeight(.semibold) |
26 .padding(.top) | 24 .padding(.top) |
27 | 25 |
28 Text(company.companyName.capitalized) | 26 Text(company.companyName.capitalized) |
29 .font(.callout) | 27 .font(.callout) |
47 } | 45 } |
48 .padding(.horizontal) | 46 .padding(.horizontal) |
49 | 47 |
50 Spacer() | 48 Spacer() |
51 | 49 |
52 if let prices = intradayPrices { | 50 LineChartView(data: company.intradayPrices, dates: nil, hours: nil, dragGesture: false) |
53 LineChartView(data: prices, dates: nil, hours: nil, dragGesture: false) | 51 .padding(.vertical) |
54 .padding(.vertical) | 52 .clipShape(RoundedRectangle(cornerRadius: 20)) |
55 .clipShape(RoundedRectangle(cornerRadius: 20)) | |
56 } | |
57 | |
58 } | 53 } |
59 ,alignment: .leading | 54 ,alignment: .leading |
60 ) | 55 ) |
61 } | 56 } |
62 } | 57 } |
63 | 58 |
64 struct StockItem_Previews: PreviewProvider { | 59 struct StockItem_Previews: PreviewProvider { |
65 static var previews: some View { | 60 static var previews: some View { |
66 StockItem( | 61 StockItem(company: CompanyModel(symbol: "aapl", companyName: "Apple Inc", latestPrice: 120.3, changePercent: 0.03, intradayPrices: [120.3])) |
67 symbol: "aapl", | |
68 company: QuoteModel(changePercent: 0.03, companyName: "Apple Inc", latestPrice: 120.3) | |
69 ) | |
70 } | 62 } |
71 } | 63 } |