comparison LazyBear/Views/Global Helpers/StockItem.swift @ 421:9b7af8e83d12

Change intraday prices model
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sat, 12 Jun 2021 15:20:04 +0200
parents 2984d8946342
children
comparison
equal deleted inserted replaced
420:523b780ad892 421:9b7af8e83d12
13 } 13 }
14 14
15 struct StockItem: View { 15 struct StockItem: View {
16 var symbol: String 16 var symbol: String
17 var company: QuoteModel 17 var company: QuoteModel
18 var intradayPrices: [IntradayPriceModel]? 18 var intradayPrices: [Double]?
19 var orientation: OrientationView 19 var orientation: OrientationView
20 var hidePriceView: Bool? 20 var hidePriceView: Bool?
21 21
22 var body: some View { 22 var body: some View {
23 if orientation == .vertical { 23 if orientation == .vertical {
41 41
42 struct StockItem_Previews: PreviewProvider { 42 struct StockItem_Previews: PreviewProvider {
43 static var previews: some View { 43 static var previews: some View {
44 StockItem( 44 StockItem(
45 symbol: "AAPL", company: QuoteModel(changePercent: 0.03, companyName: "apple inc", latestPrice: 130.3), 45 symbol: "AAPL", company: QuoteModel(changePercent: 0.03, companyName: "apple inc", latestPrice: 130.3),
46 intradayPrices: [IntradayPriceModel(open: 130.3), IntradayPriceModel(open: 132.3)], orientation: .horizontal 46 intradayPrices: [130.3, 132.3], orientation: .horizontal
47 ) 47 )
48 } 48 }
49 } 49 }
50 50
51 51
52 struct VerticalStockRow: View { 52 struct VerticalStockRow: View {
53 var symbol: String 53 var symbol: String
54 var company: QuoteModel 54 var company: QuoteModel
55 var intradayPrices: [IntradayPriceModel]? 55 var intradayPrices: [Double]?
56 56
57 var body: some View { 57 var body: some View {
58 RoundedRectangle(cornerRadius: 20) 58 RoundedRectangle(cornerRadius: 20)
59 .foregroundColor(Color(.secondarySystemBackground)) 59 .foregroundColor(Color(.secondarySystemBackground))
60 .aspectRatio(0.8, contentMode: .fit) 60 .aspectRatio(0.8, contentMode: .fit)
91 } 91 }
92 .padding(.horizontal) 92 .padding(.horizontal)
93 93
94 Spacer() 94 Spacer()
95 95
96 if let prices = intradayPrices?.compactMap { $0.open } { 96 if let prices = intradayPrices {
97 LineChartView(data: prices, dates: nil, hours: nil, dragGesture: false) 97 LineChartView(data: prices, dates: nil, hours: nil, dragGesture: false)
98 .padding(.vertical) 98 .padding(.vertical)
99 .clipShape(RoundedRectangle(cornerRadius: 20)) 99 .clipShape(RoundedRectangle(cornerRadius: 20))
100 } 100 }
101 101
107 107
108 108
109 struct HorizontalStockRow: View { 109 struct HorizontalStockRow: View {
110 var symbol: String 110 var symbol: String
111 var company: QuoteModel 111 var company: QuoteModel
112 var intradayPrices: [IntradayPriceModel]? 112 var intradayPrices: [Double]?
113 var hidePriceView: Bool 113 var hidePriceView: Bool
114 114
115 var body: some View { 115 var body: some View {
116 HStack { 116 HStack {
117 VStack(alignment: .leading) { 117 VStack(alignment: .leading) {
125 .lineLimit(1) 125 .lineLimit(1)
126 } 126 }
127 127
128 Spacer() 128 Spacer()
129 if !hidePriceView { 129 if !hidePriceView {
130 if let prices = intradayPrices?.compactMap { $0.open } { 130 if let prices = intradayPrices {
131 LineChartView(data: prices, dates: nil, hours: nil, dragGesture: false) 131 LineChartView(data: prices, dates: nil, hours: nil, dragGesture: false)
132 .frame(width: 80) 132 .frame(width: 80)
133 .padding(.vertical, 10) 133 .padding(.vertical, 10)
134 .padding(.leading) 134 .padding(.leading)
135 } 135 }