Mercurial > public > lazybear
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBearWatchOS Extension/Views/Helpers/WatchOSCompanyRow.swift Mon Jun 28 11:55:19 2021 +0200 @@ -0,0 +1,56 @@ +// +// WatchOSCompanyRow.swift +// LazyBearWatchOS Extension +// +// Created by Dennis Concepción Martín on 22/6/21. +// + +import SwiftUI + +struct WatchOSCompanyRow: View { + var company: CompanyModel + + var body: some View { + 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 WatchOSCompanyRow_Previews: PreviewProvider { + static var previews: some View { + WatchOSCompanyRow(company: + CompanyModel( + symbol: "aapl", + companyName: "Apple Inc", + latestPrice: 120.3, + changePercent: 0.03, + intradayPrices: [120.3] + ) + ) + } +}