comparison LazyBear/Views/Company/Helpers/InsiderRosterList.swift @ 447:8621ba6fd457

Fixes #48
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Wed, 23 Jun 2021 10:54:47 +0200
parents 7d1c4dc8d1d8
children
comparison
equal deleted inserted replaced
446:9cc0455bc46f 447:8621ba6fd457
7 7
8 import SwiftUI 8 import SwiftUI
9 9
10 struct InsiderRosterList: View { 10 struct InsiderRosterList: View {
11 var insiderRoster: [InsiderRosterModel] 11 var insiderRoster: [InsiderRosterModel]
12 @Binding var isPresented: Bool
13 12
14 var body: some View { 13 var body: some View {
15 NavigationView { 14 ScrollView(showsIndicators: false) {
16 ScrollView(showsIndicators: false) { 15 VStack {
17 VStack { 16 let totalPositions = insiderRoster.map { $0.position ?? 0 }.reduce(0, +) /// Get total shares owned by top 10 insiders
18 let totalPositions = insiderRoster.map { $0.position ?? 0 }.reduce(0, +) /// Get total shares owned by top 10 insiders 17 ForEach(insiderRoster, id: \.self) { insider in
19 ForEach(insiderRoster, id: \.self) { insider in 18 let percentageOfWidth = Double(insider.position ?? 0) / Double(totalPositions) /// Compute percentage of ownership for each insider
20 let percentageOfWidth = Double(insider.position ?? 0) / Double(totalPositions) /// Compute percentage of ownership for each insider 19 InsiderRosterRow(insider: insider, percentageOfWidth: CGFloat(percentageOfWidth))
21 InsiderRosterRow(insider: insider, percentageOfWidth: CGFloat(percentageOfWidth)) 20 Divider()
22 Divider()
23 }
24 }
25 .padding()
26 }
27 .navigationTitle("Top 10 Insiders")
28 .toolbar {
29 ToolbarItem(placement: .cancellationAction) {
30 Button(action: { self.isPresented.toggle() }) {
31 Image(systemName: "multiply")
32 }
33 } 21 }
34 } 22 }
23 .padding()
35 } 24 }
36 } 25 }
37 } 26 }
38 27
39 struct InsiderRosterList_Previews: PreviewProvider { 28 struct InsiderRosterList_Previews: PreviewProvider {
45 entityName: "Tim Cook", 34 entityName: "Tim Cook",
46 position: 12345, 35 position: 12345,
47 reportDate: 12345 36 reportDate: 12345
48 ) 37 )
49 ] 38 ]
50 , isPresented: .constant(true)
51 ) 39 )
52 } 40 }
53 } 41 }