Mercurial > public > lazybear
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Profile/Helpers/WatchlistCreatorRow.swift Sun May 02 12:41:20 2021 +0200 @@ -0,0 +1,54 @@ +// +// WatchlistCreatorRow.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 2/5/21. +// + +import SwiftUI + +struct WatchlistCreatorRow: View { + var company: SearchResponse + @Binding var presentationMode: PresentationMode + @ObservedObject var watchlistCreatorClass: WatchlistCreatorClass + + var body: some View { + Button(action: { saveCompany() }) { + HStack { + VStack(alignment: .leading) { + Text(company.symbol!.uppercased()) + .fontWeight(.semibold) + + Text(company.securityName ?? "-") + .font(.callout) + .fontWeight(.semibold) + .opacity(0.6) + .lineLimit(1) + } + + Spacer() + Image(systemName: "plus.circle") + .imageScale(.large) + .foregroundColor(Color(.systemBlue)) + } + .contentShape(Rectangle()) + } + .buttonStyle(PlainButtonStyle()) + } + + /* + Save company when it's selected and dismiss view + */ + private func saveCompany() { + watchlistCreatorClass.companies.append(company) + $presentationMode.wrappedValue.dismiss() + } +} + +struct WatchlistCreatorRow_Previews: PreviewProvider { + @Environment(\.presentationMode) static var presentationMode + + static var previews: some View { + WatchlistCreatorRow(company: SearchResponse(currency: "USD", exchange: nil, region: "US", securityName: "Apple Inc", symbol: "AAPL"), presentationMode: presentationMode, watchlistCreatorClass: WatchlistCreatorClass()) + } +}