comparison LazyBearWatchOS Extension/Views/Home/StockView.swift @ 454:c79a3ed3d230

StockView for WatchOS implemented
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Sun, 27 Jun 2021 20:55:05 +0200
parents
children
comparison
equal deleted inserted replaced
453:37c13ebda381 454:c79a3ed3d230
1 //
2 // StockView.swift
3 // LazyBearWatchOS Extension
4 //
5 // Created by Dennis Concepción Martín on 27/06/2021.
6 //
7
8 import SwiftUI
9 import StockCharts
10
11 struct StockView: View {
12 var symbol: String
13 @ObservedObject var company: Company
14
15 var body: some View {
16 if company.showView {
17 VStack(alignment: .leading) {
18 if let company = company.data.quote?.first {
19 Text(company.companyName)
20
21 if let latestPrice = company.latestPrice {
22 Text("\(latestPrice, specifier: "%.2f")")
23 .foregroundColor(company.changePercent ?? 0.0 < 0 ? .red: .green)
24 .font(.title2)
25 }
26
27 if let changePercent = company.changePercent {
28 Text("\(changePercent * 100, specifier: "%.2f")%")
29 .foregroundColor(changePercent < 0 ? .red: .green)
30 }
31
32 if let prices = company.intradayPrices {
33 LineChartView(data: prices, dates: nil, hours: nil, dragGesture: false)
34 .padding(.top)
35 }
36
37 Text("Real-time data")
38 .font(.footnote)
39 .opacity(0.7)
40 }
41 }
42 } else {
43 ProgressView()
44 .onAppear {
45 company.request("https://api.lazybear.app/individual/endpoint=quote/symbol=\(symbol)", .initial)
46 }
47 }
48 }
49 }
50
51 struct StockView_Previews: PreviewProvider {
52 static var previews: some View {
53 StockView(symbol: "AAPL", company: Company())
54 }
55 }