changeset 333:41c9252fc76c

Reorganizing files
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Tue, 30 Mar 2021 23:15:49 +0200
parents d82e8dd0a828
children d7927e7eeff1
files LazyBear/Views/Global Helpers/LineShape.swift LazyBear/Views/Global Helpers/LineView.swift LazyBear/Views/Home/Helpers/TradingDatesItem.swift LazyBear/Views/Home/TradingDates.swift
diffstat 4 files changed, 177 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Global Helpers/LineShape.swift	Tue Mar 30 23:15:49 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/Global Helpers/LineView.swift	Tue Mar 30 23:15:49 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/TradingDatesItem.swift	Tue Mar 30 23:15:49 2021 +0200
@@ -0,0 +1,56 @@
+//
+//  TradingDatesItem.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 30/3/21.
+//
+
+import SwiftUI
+
+struct TradingDatesItem: View {
+    @Environment(\.colorScheme) var colorScheme
+    
+    var body: some View {
+        RoundedRectangle(cornerRadius: 20)
+            .foregroundColor(Color(.secondarySystemBackground))
+            .frame(height: 100)
+            .overlay(
+                HStack {
+                    Rectangle()
+                        .frame(width: 15)
+                        .foregroundColor(Color("default"))
+                        
+                    VStack {
+                        Text("April")
+                            .fontWeight(.semibold)
+                        
+                        Text("20")
+                            .font(.title)
+                            .fontWeight(.semibold)
+                            .foregroundColor(Color("default"))
+                    }
+                    
+                    Spacer()
+                    VStack {
+                        Text("US Markets open in regular hours")
+                            .fontWeight(.semibold)
+                        
+                        Text("Random funny phrase")
+                            .font(.caption)
+                            .fontWeight(.semibold)
+                            .multilineTextAlignment(.center)
+                            .opacity(0.6)
+                    }
+                    
+                    Spacer()
+                }
+                .clipShape(RoundedRectangle(cornerRadius: 20))
+            )
+    }
+}
+
+struct TradingDatesItem_Previews: PreviewProvider {
+    static var previews: some View {
+        TradingDatesItem()
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LazyBear/Views/Home/TradingDates.swift	Tue Mar 30 23:15:49 2021 +0200
@@ -0,0 +1,31 @@
+//
+//  TradingDate.swift
+//  LazyBear
+//
+//  Created by Dennis Concepción Martín on 30/3/21.
+//
+
+import SwiftUI
+
+struct TradingDates: View {
+    
+    var body: some View {
+        NavigationView {
+            ScrollView {
+                VStack(spacing: 30) {
+                    ForEach((1..<10)) { index in
+                        TradingDatesItem()
+                    }
+                }
+                .padding()
+            }
+            .navigationTitle("Trading dates")
+        }
+    }
+}
+
+struct TradingDate_Previews: PreviewProvider {
+    static var previews: some View {
+        TradingDates()
+    }
+}