Mercurial > public > lazybear
comparison LazyBear/Views/Global Helpers/StockRow.swift @ 357:eb97439e46cd
Implement ExtensiveList in HomeView
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Thu, 15 Apr 2021 23:37:25 +0200 |
parents | LazyBear/Views/Global Helpers/StockRectangleRow.swift@5ccceb527178 |
children | f3cb5bdea8e5 |
comparison
equal
deleted
inserted
replaced
356:5385a8f8cc5c | 357:eb97439e46cd |
---|---|
1 // | |
2 // StockRow.swift | |
3 // LazyBear | |
4 // | |
5 // Created by Dennis Concepción Martín on 28/3/21. | |
6 // | |
7 | |
8 import SwiftUI | |
9 | |
10 | |
11 struct StockRow: View { | |
12 var listName: String | |
13 var list: [QuoteModel] | |
14 var nestedIntradayPrices: [String: NestedIntradayPricesModel]? | |
15 | |
16 @State private var showExtensiveList = false | |
17 | |
18 var body: some View { | |
19 VStack(alignment: .leading) { | |
20 HStack(alignment: .bottom) { | |
21 VStack(alignment: .leading) { | |
22 Text(adaptTitle(listName)) | |
23 .font(.title3) | |
24 .fontWeight(.semibold) | |
25 .padding([.top, .horizontal]) | |
26 | |
27 Text("Real-time quotes") | |
28 .font(.caption) | |
29 .opacity(0.5) | |
30 .padding(.horizontal) | |
31 } | |
32 | |
33 Spacer() | |
34 Button("See all", action: { self.showExtensiveList = true }) | |
35 .buttonStyle(BorderlessButtonStyle()) | |
36 .padding(.horizontal) | |
37 } | |
38 | |
39 ScrollView(.horizontal, showsIndicators: false) { | |
40 HStack(spacing: 20) { | |
41 ForEach(list, id: \.self) { company in | |
42 if let intradayPrices = nestedIntradayPrices?[company.symbol.uppercased()] { | |
43 StockItem(company: company, intradayPrices: intradayPrices.nestedIntradayPrices, orientation: .vertical) | |
44 } else { | |
45 StockItem(company: company, intradayPrices: nil, orientation: .vertical) | |
46 } | |
47 } | |
48 } | |
49 .padding() | |
50 } | |
51 .frame(height: 250) | |
52 } | |
53 .padding(.bottom) | |
54 .sheet(isPresented: $showExtensiveList) { | |
55 ExtensiveList(listName: adaptTitle(listName), list: list, nestedIntradayPrices: nestedIntradayPrices, latestCurrencies: nil) | |
56 } | |
57 } | |
58 } | |
59 | |
60 private func adaptTitle(_ listType: String) -> String { | |
61 if listType == "mostactive" { | |
62 return "Most active" | |
63 } else { | |
64 return listType.capitalized | |
65 } | |
66 } | |
67 | |
68 | |
69 struct StockRectangleRow_Previews: PreviewProvider { | |
70 static var previews: some View { | |
71 StockRow( | |
72 listName: "mostactive", | |
73 list: [QuoteModel(companyName: "apple inc", symbol: "aapl", latestPrice: 130.3, changePercent: 0.03)], | |
74 nestedIntradayPrices: ["AAPL": NestedIntradayPricesModel(nestedIntradayPrices: [IntradayPricesModel(open: 130.3)])] | |
75 ) | |
76 } | |
77 } |