Mercurial > public > lazybear
diff 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 |
line wrap: on
line diff
--- a/LazyBearWatchOS Extension/Views/Home/Helpers/CompanyRow.swift Sat Jun 26 17:04:29 2021 +0200 +++ b/LazyBearWatchOS Extension/Views/Home/Helpers/CompanyRow.swift Sat Jun 26 18:45:31 2021 +0200 @@ -8,13 +8,49 @@ import SwiftUI struct CompanyRow: View { + var company: CompanyModel + var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + VStack(alignment: .leading) { + HStack { + Text(company.symbol.uppercased()) + .font(.caption2) + .fontWeight(.semibold) + + Spacer() + if let changePercent = company.changePercent { + VStack { + Text("\(changePercent * 100, specifier: "%.2f")%") + .foregroundColor(changePercent < 0 ? .red: .green) + } + } + } + + if let latestPrice = company.latestPrice { + Text("\(latestPrice, specifier: "%.2f")") + .foregroundColor(company.changePercent ?? 0.0 < 0 ? .red: .green) + .font(.title2) + } + } + .padding() + .background( + RoundedRectangle(cornerRadius: 10) + .foregroundColor(company.changePercent ?? 0.0 < 0 ? .red: .green) + .opacity(0.2) + ) } } struct CompanyRow_Previews: PreviewProvider { static var previews: some View { - CompanyRow() + CompanyRow(company: + CompanyModel( + symbol: "aapl", + companyName: "Apple Inc", + latestPrice: 120.3, + changePercent: 0.03, + intradayPrices: [120.3] + ) + ) } }