Mercurial > public > lazybear
diff LazyBear/Views/Company/Helpers/InsiderRosterList.swift @ 443:ffbb1dbab531
InsiderRosterHelper implemented
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Mon, 21 Jun 2021 20:17:46 +0200 |
parents | |
children | 7d1c4dc8d1d8 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Views/Company/Helpers/InsiderRosterList.swift Mon Jun 21 20:17:46 2021 +0200 @@ -0,0 +1,52 @@ +// +// InsiderRosterList.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 21/6/21. +// + +import SwiftUI + +struct InsiderRosterList: View { + var insiderRoster: [InsiderRosterModel] + @Environment(\.presentationMode) private var insiderRosterListPresentation + + var body: some View { + NavigationView { + ScrollView(showsIndicators: false) { + VStack { + let totalPositions = insiderRoster.map { $0.position ?? 0 }.reduce(0, +) /// Get total shares owned by top 10 insiders + ForEach(insiderRoster, id: \.self) { insider in + let percentageOfWidth = Double(insider.position ?? 0) / Double(totalPositions) /// Compute percentage of ownership for each insider + InsiderRosterRow(insider: insider, percentageOfWidth: CGFloat(percentageOfWidth)) + Divider() + } + } + .padding() + } + .navigationTitle("Top 10 Insiders") + .toolbar { + ToolbarItem(placement: .cancellationAction) { + Button(action: { insiderRosterListPresentation.wrappedValue.dismiss() }) { + Image(systemName: "multiply") + } + } + } + } + } +} + +struct InsiderRosterList_Previews: PreviewProvider { + static var previews: some View { + InsiderRosterList( + insiderRoster: + [ + InsiderRosterModel( + entityName: "Tim Cook", + position: 12345, + reportDate: 12345 + ) + ] + ) + } +}