changeset 324:3e64824cca3e

Working on HomeView
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Mon, 29 Mar 2021 20:59:41 +0200
parents 65f537dae6e5
children cc3ba74d543e
files LazyBear/Assets.xcassets/Sectors/Communication Services.imageset/Communication Services.jpg LazyBear/Assets.xcassets/Sectors/Communication Services.imageset/Contents.json LazyBear/Assets.xcassets/Sectors/Consumer Discretionary.imageset/Consumer Discretionary.jpg LazyBear/Assets.xcassets/Sectors/Consumer Discretionary.imageset/Contents.json LazyBear/Assets.xcassets/Sectors/Consumer Staples.imageset/Consumer Staples.jpg LazyBear/Assets.xcassets/Sectors/Consumer Staples.imageset/Contents.json LazyBear/Assets.xcassets/Sectors/Contents.json LazyBear/Assets.xcassets/Sectors/Energy.imageset/Contents.json LazyBear/Assets.xcassets/Sectors/Energy.imageset/Energy.jpg LazyBear/Assets.xcassets/Sectors/Financials.imageset/Contents.json LazyBear/Assets.xcassets/Sectors/Financials.imageset/Financials.jpg LazyBear/Assets.xcassets/Sectors/Health Care.imageset/Contents.json LazyBear/Assets.xcassets/Sectors/Health Care.imageset/Health Care.jpg LazyBear/Assets.xcassets/Sectors/Industrials.imageset/Contents.json LazyBear/Assets.xcassets/Sectors/Industrials.imageset/Industrials.jpg LazyBear/Assets.xcassets/Sectors/Materials.imageset/Contents.json LazyBear/Assets.xcassets/Sectors/Materials.imageset/Materials.jpg LazyBear/Assets.xcassets/Sectors/Real Estate.imageset/Contents.json LazyBear/Assets.xcassets/Sectors/Real Estate.imageset/Real Estate.jpg LazyBear/Assets.xcassets/Sectors/Technology.imageset/Contents.json LazyBear/Assets.xcassets/Sectors/Technology.imageset/Technology.jpg LazyBear/Assets.xcassets/Sectors/Utilities.imageset/Contents.json LazyBear/Assets.xcassets/Sectors/Utilities.imageset/Utilities.jpg LazyBear/Tests/TestFraming.swift LazyBear/Views/Helpers/LineShape.swift LazyBear/Views/Helpers/LineView.swift LazyBear/Views/Home/Helpers/SectorItem.swift LazyBear/Views/Home/Helpers/SectorRow.swift LazyBear/Views/Home/Helpers/TopStockItem.swift LazyBear/Views/Home/Helpers/TopStockRow.swift LazyBear/Views/Home/HomeView.swift
diffstat 31 files changed, 557 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
Binary file LazyBear/Assets.xcassets/Sectors/Communication Services.imageset/Communication Services.jpg has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Assets.xcassets/Sectors/Communication Services.imageset/Contents.json	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "filename" : "Communication Services.jpg",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
Binary file LazyBear/Assets.xcassets/Sectors/Consumer Discretionary.imageset/Consumer Discretionary.jpg has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Assets.xcassets/Sectors/Consumer Discretionary.imageset/Contents.json	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "filename" : "Consumer Discretionary.jpg",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
Binary file LazyBear/Assets.xcassets/Sectors/Consumer Staples.imageset/Consumer Staples.jpg has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Assets.xcassets/Sectors/Consumer Staples.imageset/Contents.json	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "filename" : "Consumer Staples.jpg",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Assets.xcassets/Sectors/Contents.json	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,6 @@
+{
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Assets.xcassets/Sectors/Energy.imageset/Contents.json	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "filename" : "Energy.jpg",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
Binary file LazyBear/Assets.xcassets/Sectors/Energy.imageset/Energy.jpg has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Assets.xcassets/Sectors/Financials.imageset/Contents.json	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "filename" : "Financials.jpg",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
Binary file LazyBear/Assets.xcassets/Sectors/Financials.imageset/Financials.jpg has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Assets.xcassets/Sectors/Health Care.imageset/Contents.json	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "filename" : "Health Care.jpg",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
Binary file LazyBear/Assets.xcassets/Sectors/Health Care.imageset/Health Care.jpg has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Assets.xcassets/Sectors/Industrials.imageset/Contents.json	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "filename" : "Industrials.jpg",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
Binary file LazyBear/Assets.xcassets/Sectors/Industrials.imageset/Industrials.jpg has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Assets.xcassets/Sectors/Materials.imageset/Contents.json	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "filename" : "Materials.jpg",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
Binary file LazyBear/Assets.xcassets/Sectors/Materials.imageset/Materials.jpg has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Assets.xcassets/Sectors/Real Estate.imageset/Contents.json	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "filename" : "Real Estate.jpg",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
Binary file LazyBear/Assets.xcassets/Sectors/Real Estate.imageset/Real Estate.jpg has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Assets.xcassets/Sectors/Technology.imageset/Contents.json	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "filename" : "Technology.jpg",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
Binary file LazyBear/Assets.xcassets/Sectors/Technology.imageset/Technology.jpg has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Assets.xcassets/Sectors/Utilities.imageset/Contents.json	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,21 @@
+{
+  "images" : [
+    {
+      "filename" : "Utilities.jpg",
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}
Binary file LazyBear/Assets.xcassets/Sectors/Utilities.imageset/Utilities.jpg has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Tests/TestFraming.swift	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,34 @@
+//
+//  TestFraming.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 29/3/21.
+//
+
+import SwiftUI
+
+struct TestFraming: View {
+    var body: some View {
+        ZStack {
+            RoundedRectangle(cornerRadius: 20)
+                .fill(Color.blue)
+            
+            VStack {
+                Spacer()
+                Rectangle()
+                    .fill(Color.blue)
+                    .frame(height: 100)
+                    .overlay(
+                        LineView()
+                    )
+            }
+            .padding(.bottom)
+        }
+    }
+}
+
+struct TestFraming_Previews: PreviewProvider {
+    static var previews: some View {
+        TestFraming()
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Helpers/LineShape.swift	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,38 @@
+//
+//  LineShape.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 29/3/21.
+//
+
+import SwiftUI
+
+struct LineShape: Shape {
+    var width: CGFloat
+    var height: CGFloat
+    var normalizedData: [Double]
+    
+    func path(in rect: CGRect) -> Path {
+        var path = Path()
+        
+        let spaceBetweenPoints = Double(width) / Double(normalizedData.count - 1)
+        var xPoint: Double = 0
+        let initialYPoint = normalizedData.first ?? 0 * Double(height)
+        
+        path.move(to: CGPoint(x: xPoint, y: initialYPoint))
+        
+        var firstLoop = true
+        for yPoint in normalizedData {
+            if firstLoop {
+                firstLoop = false
+            } else {
+                xPoint += spaceBetweenPoints
+                let yPoint = yPoint * Double(height)
+                path.addLine(to: CGPoint(x: xPoint, y: yPoint))
+            }
+        }
+        
+        return path
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Helpers/LineView.swift	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,52 @@
+//
+//  LineView.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 29/3/21.
+//
+
+import SwiftUI
+
+struct LineView: View {
+    var body: some View {
+        GeometryReader { proxy in
+            VStack {
+                let sampleData = generateRandomSample()
+                LineShape(width: proxy.size.width, height: proxy.size.height, normalizedData: normalize(sampleData))
+                    .stroke(lineWidth: 2)
+                    .rotationEffect(.degrees(180), anchor: .center)
+                    .rotation3DEffect(.degrees(180), axis: (x: 0.0, y: 1.0, z: 0.0))
+            }
+        }
+    }
+    
+    // Normalize data
+    func normalize(_ data: [Double]) -> [Double] {
+        var normalData = [Double]()
+        let min = data.min()!
+        let max = data.max()!
+
+        for value in data {
+            let normal = (value - min) / (max - min)
+            normalData.append(normal)
+        }
+
+        return normalData
+    }
+    
+    // DELETE THIS FUNCTION ON PRODUCTION
+    private func generateRandomSample() -> [Double] {
+        var randomSample = [Double]()
+        for _ in 1..<10 {
+            randomSample.append(Double.random(in: 1...100))
+        }
+        
+        return randomSample
+    }
+}
+
+struct LineView_Previews: PreviewProvider {
+    static var previews: some View {
+        LineView()
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Home/Helpers/SectorItem.swift	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,27 @@
+//
+//  SectorItem.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 28/3/21.
+//
+
+import SwiftUI
+
+struct SectorItem: View {
+    @Environment(\.colorScheme) var colorScheme
+    
+    var body: some View {
+        Image("Technology")
+            .resizable()
+            .clipShape(Circle())
+            .overlay(Circle().stroke(colorScheme == .dark ? Color(.secondarySystemBackground) : Color.white, lineWidth: 4))
+            .shadow(color: Color.black.opacity(0.2), radius: 5)
+            .frame(width: 170, height: 170)
+    }
+}
+
+struct SectorItem_Previews: PreviewProvider {
+    static var previews: some View {
+        SectorItem()
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Home/Helpers/SectorRow.swift	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,37 @@
+//
+//  SectorRow.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 28/3/21.
+//
+
+import SwiftUI
+
+struct SectorRow: View {
+    
+    var body: some View {
+        VStack(alignment: .leading) {
+            Text("Performance by sector")
+                .font(.title3)
+                .fontWeight(.semibold)
+                .padding([.top, .horizontal])
+            
+            ScrollView(.horizontal, showsIndicators: false) {
+                HStack(spacing: 20) {
+                    ForEach((1..<10)) { _ in
+                        SectorItem()
+                    }
+                }
+                .padding()
+            }
+            .frame(height: 170)
+        }
+        .padding(.bottom)
+    }
+}
+
+struct SectorRow_Previews: PreviewProvider {
+    static var previews: some View {
+        SectorRow()
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Home/Helpers/TopStockItem.swift	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,58 @@
+//
+//  TopStockItem.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 28/3/21.
+//
+
+import SwiftUI
+
+struct TopStockItem: View {
+    @Environment(\.colorScheme) var colorScheme
+    
+    var body: some View {
+            RoundedRectangle(cornerRadius: 20)
+                .foregroundColor(colorScheme == .dark ? Color(.secondarySystemBackground) : Color.white)
+                .aspectRatio(0.8, contentMode: .fit)
+                .clipShape(RoundedRectangle(cornerRadius: 20))
+                .shadow(color: Color.black.opacity(0.2), radius: 5)
+                .overlay(
+                    VStack(alignment: .leading) {
+                        Group {
+                            Text("Symbol".uppercased())
+                                .fontWeight(.semibold)
+                                .padding(.top)
+                            
+                            Text("Company name".capitalized)
+                                .fontWeight(.semibold)
+                                .opacity(0.6)
+                            
+                            Text("$120.20")
+                                .fontWeight(.semibold)
+                                .padding(.top)
+                            
+                            Text("+\(1.22, specifier: "%.2f")%")
+                                .fontWeight(.semibold)
+                                
+                        }
+                        .padding(.horizontal)
+                        
+                        Spacer()
+                         
+                        
+                        LineView()
+                            .padding(.vertical)
+                            .clipped()
+                            
+                            
+                    }
+                )
+    }
+}
+
+struct TopStockItem_Previews: PreviewProvider {
+    static var previews: some View {
+        TopStockItem()
+
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Home/Helpers/TopStockRow.swift	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,38 @@
+//
+//  TopStockRow.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 28/3/21.
+//
+
+import SwiftUI
+
+struct TopStockRow: View {
+    var keyTitle: String
+    
+    var body: some View {
+        VStack(alignment: .leading) {
+            Text(keyTitle)
+                .font(.title3)
+                .fontWeight(.semibold)
+                .padding([.top, .horizontal])
+            
+            ScrollView(.horizontal, showsIndicators: false) {
+                HStack(spacing: 20) {
+                    ForEach((1..<10)) { _ in
+                        TopStockItem()
+                    }
+                }
+                .padding()
+            }
+            .frame(height: 250)
+        }
+        .padding(.bottom)
+    }
+}
+
+struct TopStockRow_Previews: PreviewProvider {
+    static var previews: some View {
+        TopStockRow(keyTitle: "Sample title")
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Home/HomeView.swift	Mon Mar 29 20:59:41 2021 +0200
@@ -0,0 +1,36 @@
+//
+//  HomeView.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 28/3/21.
+//
+
+import SwiftUI
+
+struct HomeView: View {
+    
+    var body: some View {
+        NavigationView {
+            List {
+                SectorRow()
+                    .listRowInsets(EdgeInsets())
+                
+                let keyTitles = ["Top gainers", "Top losers", "Most active"]
+                ForEach(keyTitles, id: \.self) { keyTitle in
+                    TopStockRow(keyTitle: keyTitle)
+                    
+                }
+                .listRowInsets(EdgeInsets())
+            }
+            .navigationTitle("Home")
+            .navigationBarTitleDisplayMode(.inline)
+            .navigationViewStyle(StackNavigationViewStyle())
+        }
+    }
+}
+
+struct HomeView_Previews: PreviewProvider {
+    static var previews: some View {
+        HomeView()
+    }
+}