Mercurial > public > lazybear
comparison LazyBear/Views/Global Helpers/PriceView.swift @ 398:933546fa5651
Implementing CompanyView
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Sun, 09 May 2021 00:07:44 +0200 |
parents | eb97439e46cd |
children | dc8dccd18e86 |
comparison
equal
deleted
inserted
replaced
397:6f04495c462d | 398:933546fa5651 |
---|---|
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 struct PriceView: View { | 10 struct PriceView: View { |
11 var latestPrice: Double | 11 var latestPrice: Double |
12 var changePercent: Double | 12 var changePercent: Double |
13 var align: HorizontalAlignment | 13 var style: PriceViewStyle |
14 | 14 |
15 var body: some View { | 15 var body: some View { |
16 VStack(alignment: align) { | 16 VStack(alignment: style.alignment) { |
17 Text("$\(latestPrice, specifier: "%.2f")") | 17 Text("$\(latestPrice, specifier: "%.2f")") |
18 .foregroundColor(changePercent < 0 ? .red: .green) | 18 .foregroundColor(changePercent < 0 ? .red: .green) |
19 .fontWeight(.semibold) | 19 .font(style.priceFont) |
20 .fontWeight(style.priceFontWeight) | |
20 | 21 |
21 Text("\(changePercent*100, specifier: "%.2f")%") | 22 Text("\(changePercent*100, specifier: "%.2f")%") |
22 .foregroundColor(changePercent < 0 ? .red: .green) | 23 .foregroundColor(changePercent < 0 ? .red: .green) |
23 .font(.callout) | 24 .font(style.percentFont) |
24 .fontWeight(.semibold) | 25 .fontWeight(style.percentFontWeight) |
25 } | 26 } |
26 } | 27 } |
27 } | 28 } |
28 | 29 |
29 | 30 |
30 struct PriceView_Previews: PreviewProvider { | 31 struct PriceView_Previews: PreviewProvider { |
31 static var previews: some View { | 32 static var previews: some View { |
32 PriceView(latestPrice: 120.30, changePercent: 0.03, align: .leading) | 33 PriceView( |
34 latestPrice: 120.30, | |
35 changePercent: 0.03, | |
36 style: PriceViewStyle( | |
37 alignment: .leading, | |
38 priceFont: .body, | |
39 priceFontWeight: .semibold, | |
40 percentFont: .callout, | |
41 percentFontWeight: .semibold | |
42 ) | |
43 ) | |
33 } | 44 } |
34 } | 45 } |