Mercurial > public > lazybear
comparison LazyBear/Views/Global Helpers/StockRectangleRow.swift @ 346:80bfa88c6b0f
Implementing Prop API
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Sun, 11 Apr 2021 19:55:47 +0200 |
parents | fde2b30c719e |
children | 5ccceb527178 |
comparison
equal
deleted
inserted
replaced
345:fde2b30c719e | 346:80bfa88c6b0f |
---|---|
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 | 10 |
11 struct StockRectangleRow: View { | 11 struct StockRectangleRow: View { |
12 var listType: String | 12 var listName: String |
13 var list: [CompanyQuoteModel] | 13 var list: [QuoteModel] |
14 var intradayPrices: [String: [IntradayPricesResult]] | 14 var nestedIntradayPrices: [String: NestedIntradayPricesModel]? |
15 | 15 |
16 var body: some View { | 16 var body: some View { |
17 VStack(alignment: .leading) { | 17 VStack(alignment: .leading) { |
18 Text(adaptTitle(listType)) | 18 Text(adaptTitle(listName)) |
19 .font(.title3) | 19 .font(.title3) |
20 .fontWeight(.semibold) | 20 .fontWeight(.semibold) |
21 .padding([.top, .horizontal]) | 21 .padding([.top, .horizontal]) |
22 | 22 |
23 ScrollView(.horizontal, showsIndicators: false) { | 23 ScrollView(.horizontal, showsIndicators: false) { |
24 HStack(spacing: 20) { | 24 HStack(spacing: 20) { |
25 ForEach(list, id: \.self) { company in | 25 ForEach(list, id: \.self) { company in |
26 StockItem(company: company, intradayPrices: self.intradayPrices[company.symbol]!) | 26 if let intradayPrices = nestedIntradayPrices?[company.symbol.uppercased()] { |
27 StockItem(company: company, intradayPrices: intradayPrices.nestedIntradayPrices) | |
28 } else { | |
29 StockItem(company: company, intradayPrices: nil) | |
30 } | |
27 } | 31 } |
28 } | 32 } |
29 .padding() | 33 .padding() |
30 } | 34 } |
31 .frame(height: 250) | 35 .frame(height: 250) |
32 } | 36 } |
33 .padding(.bottom) | 37 .padding(.bottom) |
38 } | |
39 | |
40 private func testPrint(_ test: Any) -> Text { | |
41 print(test) | |
42 | |
43 return Text("") | |
34 } | 44 } |
35 } | 45 } |
36 | 46 |
37 private func adaptTitle(_ listType: String) -> String { | 47 private func adaptTitle(_ listType: String) -> String { |
38 if listType == "mostactive" { | 48 if listType == "mostactive" { |
43 } | 53 } |
44 | 54 |
45 | 55 |
46 struct StockRectangleRow_Previews: PreviewProvider { | 56 struct StockRectangleRow_Previews: PreviewProvider { |
47 static var previews: some View { | 57 static var previews: some View { |
48 StockRectangleRow(listType: "gainers", list: [CompanyQuoteModel(companyName: "apple inc", symbol: "aapl", latestPrice: 120.30, changePercent: 0.034)], intradayPrices: ["aapl": [IntradayPricesResult(open: 130.3)]]) | 58 StockRectangleRow( |
59 listName: "mostactive", | |
60 list: [QuoteModel(companyName: "apple inc", symbol: "aapl", latestPrice: 130.3, changePercent: 0.03)], | |
61 nestedIntradayPrices: ["AAPL": NestedIntradayPricesModel(nestedIntradayPrices: [IntradayPricesModel(marketOpen: 130.3)])] | |
62 ) | |
49 } | 63 } |
50 } | 64 } |