comparison LazyBear/Views/Global Helpers/StockItem.swift @ 375:f3cb5bdea8e5

Update Codable requests in HomeView
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Wed, 21 Apr 2021 16:19:50 +0200
parents eb97439e46cd
children a7e2c5a7b4f6
comparison
equal deleted inserted replaced
374:d402bfa367c2 375:f3cb5bdea8e5
10 enum OrientationView { 10 enum OrientationView {
11 case horizontal, vertical 11 case horizontal, vertical
12 } 12 }
13 13
14 struct StockItem: View { 14 struct StockItem: View {
15 var symbol: String
15 var company: QuoteModel 16 var company: QuoteModel
16 var intradayPrices: [IntradayPricesModel]? 17 var intradayPrices: [IntradayPriceModel]?
17 var orientation: OrientationView 18 var orientation: OrientationView
18 19
19 var body: some View { 20 var body: some View {
20 if orientation == .vertical { 21 if orientation == .vertical {
21 return AnyView(VerticalStockRow(company: company, intradayPrices: intradayPrices)) 22 return AnyView(VerticalStockRow(symbol: symbol, company: company, intradayPrices: intradayPrices))
22 } else { 23 } else {
23 return AnyView(HorizontalStockRow(company: company, intradayPrices: intradayPrices)) 24 return AnyView(HorizontalStockRow(symbol: symbol, company: company, intradayPrices: intradayPrices))
24 } 25 }
25 } 26 }
26 } 27 }
27 28
28 struct StockItem_Previews: PreviewProvider { 29 struct StockItem_Previews: PreviewProvider {
29 static var previews: some View { 30 static var previews: some View {
30 StockItem( 31 StockItem(
31 company: QuoteModel(companyName: "apple inc", symbol: "aapl", latestPrice: 130.3, changePercent: 0.03), 32 symbol: "AAPL", company: QuoteModel(changePercent: 0.03, companyName: "apple inc", latestPrice: 130.3),
32 intradayPrices: [IntradayPricesModel(open: 130.3), IntradayPricesModel(open: 132.3)], orientation: .horizontal 33 intradayPrices: [IntradayPriceModel(open: 130.3), IntradayPriceModel(open: 132.3)], orientation: .horizontal
33 ) 34 )
34 } 35 }
35 } 36 }
36 37
37 38
38 struct VerticalStockRow: View { 39 struct VerticalStockRow: View {
40 var symbol: String
39 var company: QuoteModel 41 var company: QuoteModel
40 var intradayPrices: [IntradayPricesModel]? 42 var intradayPrices: [IntradayPriceModel]?
41 43
42 var body: some View { 44 var body: some View {
43 RoundedRectangle(cornerRadius: 20) 45 RoundedRectangle(cornerRadius: 20)
44 .foregroundColor(Color(.secondarySystemBackground)) 46 .foregroundColor(Color(.secondarySystemBackground))
45 .aspectRatio(0.8, contentMode: .fit) 47 .aspectRatio(0.8, contentMode: .fit)
46 .clipShape(RoundedRectangle(cornerRadius: 20)) 48 .clipShape(RoundedRectangle(cornerRadius: 20))
47 .overlay( 49 .overlay(
48 VStack(alignment: .leading) { 50 VStack(alignment: .leading) {
49 Group { 51 Group {
50 Text(company.symbol.uppercased()) 52 Text(symbol.uppercased())
51 .fontWeight(.semibold) 53 .fontWeight(.semibold)
52 .padding(.top) 54 .padding(.top)
53 55
54 Text(company.companyName.capitalized) 56 Text(company.companyName.capitalized)
55 .font(.callout) 57 .font(.callout)
78 } 80 }
79 } 81 }
80 82
81 83
82 struct HorizontalStockRow: View { 84 struct HorizontalStockRow: View {
85 var symbol: String
83 var company: QuoteModel 86 var company: QuoteModel
84 var intradayPrices: [IntradayPricesModel]? 87 var intradayPrices: [IntradayPriceModel]?
85 88
86 var body: some View { 89 var body: some View {
87 HStack { 90 HStack {
88 VStack(alignment: .leading) { 91 VStack(alignment: .leading) {
89 Text(company.symbol.uppercased()) 92 Text(symbol.uppercased())
90 .fontWeight(.semibold) 93 .fontWeight(.semibold)
91 94
92 Text(company.companyName.capitalized) 95 Text(company.companyName.capitalized)
93 .font(.callout) 96 .font(.callout)
94 .fontWeight(.semibold) 97 .fontWeight(.semibold)