comparison LazyBearWatchOS Extension/Views/Home/Helpers/CompanyRow.swift @ 452:bb69f9d1d20f

Implement HomeView in WatchOS
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Sat, 26 Jun 2021 18:45:31 +0200
parents 8621ba6fd457
children
comparison
equal deleted inserted replaced
451:bb130738b816 452:bb69f9d1d20f
6 // 6 //
7 7
8 import SwiftUI 8 import SwiftUI
9 9
10 struct CompanyRow: View { 10 struct CompanyRow: View {
11 var company: CompanyModel
12
11 var body: some View { 13 var body: some View {
12 Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) 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 )
13 } 41 }
14 } 42 }
15 43
16 struct CompanyRow_Previews: PreviewProvider { 44 struct CompanyRow_Previews: PreviewProvider {
17 static var previews: some View { 45 static var previews: some View {
18 CompanyRow() 46 CompanyRow(company:
47 CompanyModel(
48 symbol: "aapl",
49 companyName: "Apple Inc",
50 latestPrice: 120.3,
51 changePercent: 0.03,
52 intradayPrices: [120.3]
53 )
54 )
19 } 55 }
20 } 56 }