comparison LazyBear/Views/Global Helpers/StockItem.swift @ 379:a7e2c5a7b4f6

Implement onDelete in watchlists
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Thu, 22 Apr 2021 23:44:20 +0200
parents f3cb5bdea8e5
children 6303385b3629
comparison
equal deleted inserted replaced
378:6802c2393203 379:a7e2c5a7b4f6
14 struct StockItem: View { 14 struct StockItem: View {
15 var symbol: String 15 var symbol: String
16 var company: QuoteModel 16 var company: QuoteModel
17 var intradayPrices: [IntradayPriceModel]? 17 var intradayPrices: [IntradayPriceModel]?
18 var orientation: OrientationView 18 var orientation: OrientationView
19 var hidePriceView: Bool?
19 20
20 var body: some View { 21 var body: some View {
21 if orientation == .vertical { 22 if orientation == .vertical {
22 return AnyView(VerticalStockRow(symbol: symbol, company: company, intradayPrices: intradayPrices)) 23 return AnyView(VerticalStockRow(symbol: symbol, company: company, intradayPrices: intradayPrices))
23 } else { 24 } else {
24 return AnyView(HorizontalStockRow(symbol: symbol, company: company, intradayPrices: intradayPrices)) 25 return AnyView(HorizontalStockRow(symbol: symbol, company: company, intradayPrices: intradayPrices, hidePriceView: hidePriceView ?? false))
25 } 26 }
26 } 27 }
27 } 28 }
28 29
29 struct StockItem_Previews: PreviewProvider { 30 struct StockItem_Previews: PreviewProvider {
83 84
84 struct HorizontalStockRow: View { 85 struct HorizontalStockRow: View {
85 var symbol: String 86 var symbol: String
86 var company: QuoteModel 87 var company: QuoteModel
87 var intradayPrices: [IntradayPriceModel]? 88 var intradayPrices: [IntradayPriceModel]?
89 var hidePriceView: Bool
88 90
89 var body: some View { 91 var body: some View {
90 HStack { 92 HStack {
91 VStack(alignment: .leading) { 93 VStack(alignment: .leading) {
92 Text(symbol.uppercased()) 94 Text(symbol.uppercased())
98 .opacity(0.6) 100 .opacity(0.6)
99 .lineLimit(1) 101 .lineLimit(1)
100 } 102 }
101 103
102 Spacer() 104 Spacer()
103 if let prices = intradayPrices?.compactMap { $0.open } { 105 if !hidePriceView {
104 LineView(data: prices) 106 if let prices = intradayPrices?.compactMap { $0.open } {
105 .foregroundColor(company.changePercent < 0 ? .red: .green) 107 LineView(data: prices)
106 .frame(width: 80) 108 .foregroundColor(company.changePercent < 0 ? .red: .green)
107 .padding(.vertical, 10) 109 .frame(width: 80)
108 .padding(.leading) 110 .padding(.vertical, 10)
111 .padding(.leading)
112 }
113
114 PriceView(latestPrice: company.latestPrice, changePercent: company.changePercent, align: .trailing)
115 // Center PriceView with the other rows
116 .frame(minWidth: 80, alignment: .trailing)
109 } 117 }
110
111 PriceView(latestPrice: company.latestPrice, changePercent: company.changePercent, align: .trailing)
112 // Avoid moving LineView along the HStack when numbers increases
113 .frame(minWidth: 80, alignment: .trailing)
114 } 118 }
115 .padding(5) 119 .padding(5)
116 } 120 }
117 } 121 }