comparison LazyBear/Views/Profile/Helpers/WatchlistCreatorRow.swift @ 393:0a4c399170c4

Implementing WatchlistCreator
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sun, 02 May 2021 12:41:20 +0200
parents
children c78d5b5b3bda
comparison
equal deleted inserted replaced
392:13f3578def61 393:0a4c399170c4
1 //
2 // WatchlistCreatorRow.swift
3 // LazyBear
4 //
5 // Created by Dennis Concepción Martín on 2/5/21.
6 //
7
8 import SwiftUI
9
10 struct WatchlistCreatorRow: View {
11 var company: SearchResponse
12 @Binding var presentationMode: PresentationMode
13 @ObservedObject var watchlistCreatorClass: WatchlistCreatorClass
14
15 var body: some View {
16 Button(action: { saveCompany() }) {
17 HStack {
18 VStack(alignment: .leading) {
19 Text(company.symbol!.uppercased())
20 .fontWeight(.semibold)
21
22 Text(company.securityName ?? "-")
23 .font(.callout)
24 .fontWeight(.semibold)
25 .opacity(0.6)
26 .lineLimit(1)
27 }
28
29 Spacer()
30 Image(systemName: "plus.circle")
31 .imageScale(.large)
32 .foregroundColor(Color(.systemBlue))
33 }
34 .contentShape(Rectangle())
35 }
36 .buttonStyle(PlainButtonStyle())
37 }
38
39 /*
40 Save company when it's selected and dismiss view
41 */
42 private func saveCompany() {
43 watchlistCreatorClass.companies.append(company)
44 $presentationMode.wrappedValue.dismiss()
45 }
46 }
47
48 struct WatchlistCreatorRow_Previews: PreviewProvider {
49 @Environment(\.presentationMode) static var presentationMode
50
51 static var previews: some View {
52 WatchlistCreatorRow(company: SearchResponse(currency: "USD", exchange: nil, region: "US", securityName: "Apple Inc", symbol: "AAPL"), presentationMode: presentationMode, watchlistCreatorClass: WatchlistCreatorClass())
53 }
54 }