Mercurial > public > lazybear
comparison LazyBear/Views/Home/Helpers/StockRow.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 | LazyBear/Views/Global Helpers/StockRow.swift@9b7af8e83d12 |
children | 4effac4733b0 |
comparison
equal
deleted
inserted
replaced
423:bdfdf3a1b34e | 424:6dd97877f575 |
---|---|
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 list: [String: [String: QuoteModel]] | |
13 var intradayPrices: [String: [Double]]? | |
14 | |
15 @State private var showList = false | |
16 | |
17 var body: some View { | |
18 let listName = list.first!.key | |
19 VStack(alignment: .leading) { | |
20 HStack(alignment: .bottom) { | |
21 VStack(alignment: .leading) { | |
22 Text(adaptListTitle(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: { showList = true }) | |
35 .buttonStyle(BorderlessButtonStyle()) | |
36 .padding(.horizontal) | |
37 } | |
38 | |
39 ScrollView(.horizontal, showsIndicators: false) { | |
40 HStack(spacing: 20) { | |
41 let companies = list[listName] | |
42 ForEach(Array(companies!.keys), id: \.self) { symbol in | |
43 StockItem(symbol: symbol, company: companies![symbol]!, intradayPrices: intradayPrices![symbol]) | |
44 } | |
45 } | |
46 .padding() | |
47 } | |
48 .frame(height: 250) | |
49 } | |
50 .padding(.bottom) | |
51 .sheet(isPresented: $showList) { | |
52 StockSheet(listName: adaptListTitle(listName), companies: list[list.first!.key]!, intradayPrices: intradayPrices) | |
53 } | |
54 } | |
55 | |
56 /* | |
57 Get list keys (mostactive, losers, active) and adapt them to diplay | |
58 */ | |
59 private func adaptListTitle(_ title: String) -> String { | |
60 if title == "mostactive" { | |
61 return "Most active" | |
62 } else { | |
63 return title.capitalized | |
64 } | |
65 } | |
66 } | |
67 | |
68 | |
69 struct StockRectangleRow_Previews: PreviewProvider { | |
70 static var previews: some View { | |
71 StockRow( | |
72 list: ["mostactive": ["AAPL": QuoteModel(changePercent: 0.03, companyName: "Apple Inc", latestPrice: 130.3)]], | |
73 intradayPrices: ["AAPL": [130.2]] | |
74 ) | |
75 } | |
76 } |