Mercurial > public > lazybear
view LazyBear/Views/Search/CompanyList.swift @ 391:8ec37b2baafd
Implementing CreateNewWatchlist
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Fri, 30 Apr 2021 20:25:52 +0200 |
parents | 6303385b3629 |
children | 13f3578def61 |
line wrap: on
line source
// // CompanyList.swift // LazyBear // // Created by Dennis Concepción Martín on 3/4/21. // import SwiftUI struct CompanyList: View { var searchResult: [SearchResponse] // Only unseful when it's called from Profile View var calledFromProfileView: Bool? var newWatchlistClass: NewWatchlistClass? var body: some View { List(searchResult, id: \.self) { company in SearchedCompanyItem(company: company, calledFromProfileView: calledFromProfileView) .if(calledFromProfileView ?? false ) { content in Button(action: { newWatchlistClass!.companies.append(company) }) { content } } } } } /* Wrap view on condition */ extension View { @ViewBuilder func `if`<Content: View>(_ conditional: Bool, content: (Self) -> Content) -> some View { if conditional { content(self) } else { NavigationLink(destination: Text("Hello")) { self } } } } struct CompanyList_Previews: PreviewProvider { static var previews: some View { CompanyList(searchResult: [SearchResponse(currency: "USD", region: "US", securityName: "aaple inc", symbol: "aapl"), SearchResponse(currency: "USD", region: "US", securityName: "aaple inc", symbol: "aapl"), SearchResponse(currency: "USD", region: "US", securityName: "aaple inc", symbol: "aapl"), SearchResponse(currency: "USD", region: "US", securityName: "aaple inc", symbol: "aapl"), SearchResponse(currency: "USD", region: "US", securityName: "aaple inc", symbol: "aapl")]) } }