Mercurial > public > lazybear
view LazyBear/Views/Home/Helpers/StockItem.swift @ 457:c6913f0ce46e
Minor UI Updates
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Mon, 28 Jun 2021 14:03:50 +0200 |
parents | 417148200aaf |
children |
line wrap: on
line source
// // StockItem.swift // LazyBear // // Created by Dennis Concepción Martín on 13/6/21. // import SwiftUI import StockCharts struct StockItem: View { var company: CompanyModel @Environment(\.colorScheme) private var colorScheme var body: some View { RoundedRectangle(cornerRadius: 20) .foregroundColor(Color("customSecondaryBackground")) .aspectRatio(0.8, contentMode: .fit) .clipShape(RoundedRectangle(cornerRadius: 20)) .if(colorScheme == .light) { content in content.shadow(color: Color(.systemGray).opacity(0.25), radius: 10, x: 0.0, y: 0.0) } .overlay( VStack(alignment: .leading) { Group { Text(company.symbol.uppercased()) .fontWeight(.semibold) .padding(.top) Text(company.companyName.capitalized) .font(.callout) .fontWeight(.semibold) .opacity(0.6) .lineLimit(1) if let latestPrice = company.latestPrice, let changePercent = company.changePercent { VStack(alignment: .leading) { Text("\(latestPrice, specifier: "%.2f")") .foregroundColor(changePercent < 0 ? .red: .green) .fontWeight(.semibold) Text("\(changePercent * 100, specifier: "%.2f")%") .foregroundColor(changePercent < 0 ? .red: .green) .font(.callout) .fontWeight(.semibold) } .padding(.top) } } .padding(.horizontal) Spacer() LineChartView(data: company.intradayPrices, dates: nil, hours: nil, dragGesture: false) .padding(.vertical) .clipShape(RoundedRectangle(cornerRadius: 20)) } ,alignment: .leading ) } } struct StockItem_Previews: PreviewProvider { static var previews: some View { StockItem(company: CompanyModel(symbol: "aapl", companyName: "Apple Inc", latestPrice: 120.3, changePercent: 0.03, intradayPrices: [120.3])) } }