Mercurial > public > lazybear
comparison LazyBearWatchOS Extension/Views/Helpers/WatchOSCompanyRow.swift @ 455:b560babcd5ed
WatchOS views implemented
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Mon, 28 Jun 2021 11:55:19 +0200 |
parents | LazyBearWatchOS Extension/Views/Home/Helpers/CompanyRow.swift@bb69f9d1d20f |
children |
comparison
equal
deleted
inserted
replaced
454:c79a3ed3d230 | 455:b560babcd5ed |
---|---|
1 // | |
2 // WatchOSCompanyRow.swift | |
3 // LazyBearWatchOS Extension | |
4 // | |
5 // Created by Dennis Concepción Martín on 22/6/21. | |
6 // | |
7 | |
8 import SwiftUI | |
9 | |
10 struct WatchOSCompanyRow: View { | |
11 var company: CompanyModel | |
12 | |
13 var body: some View { | |
14 VStack(alignment: .leading) { | |
15 HStack { | |
16 Text(company.symbol.uppercased()) | |
17 .font(.caption2) | |
18 .fontWeight(.semibold) | |
19 | |
20 Spacer() | |
21 if let changePercent = company.changePercent { | |
22 VStack { | |
23 Text("\(changePercent * 100, specifier: "%.2f")%") | |
24 .foregroundColor(changePercent < 0 ? .red: .green) | |
25 } | |
26 } | |
27 } | |
28 | |
29 if let latestPrice = company.latestPrice { | |
30 Text("\(latestPrice, specifier: "%.2f")") | |
31 .foregroundColor(company.changePercent ?? 0.0 < 0 ? .red: .green) | |
32 .font(.title2) | |
33 } | |
34 } | |
35 .padding() | |
36 .background( | |
37 RoundedRectangle(cornerRadius: 10) | |
38 .foregroundColor(company.changePercent ?? 0.0 < 0 ? .red: .green) | |
39 .opacity(0.2) | |
40 ) | |
41 } | |
42 } | |
43 | |
44 struct WatchOSCompanyRow_Previews: PreviewProvider { | |
45 static var previews: some View { | |
46 WatchOSCompanyRow(company: | |
47 CompanyModel( | |
48 symbol: "aapl", | |
49 companyName: "Apple Inc", | |
50 latestPrice: 120.3, | |
51 changePercent: 0.03, | |
52 intradayPrices: [120.3] | |
53 ) | |
54 ) | |
55 } | |
56 } |