changeset 297:46dfb60e0874

Implement WelcomeView
author Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com>
date Sun, 21 Mar 2021 19:56:48 +0100
parents b481783c32c0
children a5ca835a4ab1
files LazyBear/ContentView.swift LazyBear/LazyBear.xcdatamodeld/LazyBear.xcdatamodel/contents LazyBear/LazyBearApp.swift LazyBear/Persistence.swift LazyBear/Views/OnboardView.swift LazyBear/Views/WelcomeView.swift
diffstat 6 files changed, 180 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/LazyBear/ContentView.swift	Sun Mar 21 19:56:24 2021 +0100
+++ b/LazyBear/ContentView.swift	Sun Mar 21 19:56:48 2021 +0100
@@ -9,7 +9,7 @@
 
 struct ContentView: View {
     var body: some View {
-        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
+        Text("Hello world")
     }
 }
 
--- a/LazyBear/LazyBear.xcdatamodeld/LazyBear.xcdatamodel/contents	Sun Mar 21 19:56:24 2021 +0100
+++ b/LazyBear/LazyBear.xcdatamodeld/LazyBear.xcdatamodel/contents	Sun Mar 21 19:56:48 2021 +0100
@@ -1,22 +1,9 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="17709" systemVersion="20D74" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
-    <entity name="Company" representedClassName="Company" syncable="YES">
-        <attribute name="cik" optional="YES" attributeType="String"/>
-        <attribute name="currency" optional="YES" attributeType="String"/>
-        <attribute name="exchange" optional="YES" attributeType="String"/>
-        <attribute name="exchangeName" optional="YES" attributeType="String"/>
-        <attribute name="name" optional="YES" attributeType="String"/>
-        <attribute name="region" optional="YES" attributeType="String"/>
-        <attribute name="symbol" optional="YES" attributeType="String"/>
-    </entity>
-    <entity name="UserSettings" representedClassName="UserSettings" syncable="YES">
-        <attribute name="appIcon" optional="YES" attributeType="String"/>
-        <attribute name="changedAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
-        <attribute name="newsLanguage" optional="YES" attributeType="String"/>
-        <attribute name="theme" optional="YES" attributeType="String"/>
+<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="17709" systemVersion="20D91" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
+    <entity name="Entity" representedClassName="Entity" syncable="YES" codeGenerationType="class">
+        <attribute name="attribute" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
     </entity>
     <elements>
-        <element name="Company" positionX="-63" positionY="-9" width="128" height="134"/>
-        <element name="UserSettings" positionX="-63" positionY="45" width="128" height="89"/>
+        <element name="Entity" positionX="-63" positionY="-18" width="128" height="44"/>
     </elements>
 </model>
\ No newline at end of file
--- a/LazyBear/LazyBearApp.swift	Sun Mar 21 19:56:24 2021 +0100
+++ b/LazyBear/LazyBearApp.swift	Sun Mar 21 19:56:48 2021 +0100
@@ -10,21 +10,27 @@
 @main
 struct LazyBearApp: App {
     let persistenceController = PersistenceController.shared  // Core Data init
-    
-    // Start ObservedObjects
-    @ObservedObject var hudManager = HudManager()
-    @ObservedObject var companyOption = CompanyOption()
-    @ObservedObject var deviceSize = DeviceSize()
-    @ObservedObject var hapticsManager = HapticsManager()
 
     var body: some Scene {
         WindowGroup {
+            if isAppAlreadyLaunchedOnce() {
             ContentView()
                 .environment(\.managedObjectContext, persistenceController.container.viewContext)
-                .environmentObject(hudManager)
-                .environmentObject(companyOption)
-                .environmentObject(deviceSize)
-                .environmentObject(hapticsManager)
+            } else {
+                WelcomeView()
+            }
+        }
+    }
+    
+    private func isAppAlreadyLaunchedOnce() -> Bool {
+        let defaults = UserDefaults.standard
+        
+        if let isAppAlreadyLaunchedOnce = defaults.string(forKey: "IsAppAlreadyLaunchedOnce") {
+            print("App already launched : \(isAppAlreadyLaunchedOnce)")
+            
+            return true
+        } else {
+            return false
         }
     }
 }
--- a/LazyBear/Persistence.swift	Sun Mar 21 19:56:24 2021 +0100
+++ b/LazyBear/Persistence.swift	Sun Mar 21 19:56:48 2021 +0100
@@ -14,14 +14,8 @@
         let result = PersistenceController(inMemory: true)
         let viewContext = result.container.viewContext
         for _ in 0..<10 {
-            let company = Company(context: viewContext)
-            company.name = "apple inc"
-            company.symbol = "aapl"
-            company.cik = "123"
-            company.currency = "USD"
-            company.exchange = "NYSE"
-            company.exchangeName = "New York Stock Exchange"
-            company.region = "US"
+            let entity = Entity(context: viewContext)
+            entity.attribute = 1
     
         }
         do {
--- a/LazyBear/Views/OnboardView.swift	Sun Mar 21 19:56:24 2021 +0100
+++ b/LazyBear/Views/OnboardView.swift	Sun Mar 21 19:56:48 2021 +0100
@@ -7,12 +7,119 @@
 
 import SwiftUI
 
+extension Animation {
+    static func ripple(index: Int) -> Animation {
+        Animation.spring(dampingFraction: 0.5)
+            .speed(2)
+            .delay(0.03 * Double(index))
+    }
+}
+
+class OnboardRowItems {
+    var icons = ["heart.fill", "chart.bar.fill", "paintbrush.fill"]
+    var iconColors: [Color] = [.red, .blue, .green]
+    var headlines = ["Your stocks at a glance", "Interactive charts", "New design"]
+    var bodyTexts = ["Easily create watchlists with your favourite companies.", "Long press, drag, tap and have fun with the charts.", "Modern, clean and neat without losing simplicty."]
+}
 struct OnboardView: View {
+    let onboardRowItems = OnboardRowItems()
+    @State private var showingButton = false
+    @State private var showOnboardRows = false
+    @State var showContentView = false
+    
     var body: some View {
-        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
+        if !showContentView {
+            GeometryReader { geo in
+                VStack(alignment: .leading) {
+                    Text("What's new")
+                        .font(.system(size: 50, weight: .black))
+                        .padding(.bottom)
+                        .opacity(showOnboardRows ? 1: 0)
+                        .animation(.easeInOut)
+                    
+                    ForEach((0..<3), id: \.self) { index in
+                        if showOnboardRows {
+                            OnboardRow(icon: onboardRowItems.icons[index], iconColor: onboardRowItems.iconColors[index], headline: onboardRowItems.headlines[index], bodyText: onboardRowItems.bodyTexts[index], position: index+1)
+                                .transition(.slide)
+                                .animation(.ripple(index: index))
+                        }
+                    }
+                    Spacer()
+                    OnboardButton(showContentView: $showContentView)
+                        .offset(y: showingButton ? 0 : 200)
+                        .animation(.easeInOut)
+                    
+                }
+                .onAppear {
+                    DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
+                        self.showingButton = true
+                    }
+                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
+                        self.showOnboardRows = true
+                    }
+                }
+                .padding(geo.size.width * 0.15)
+            }
+        } else {
+            ContentView()
+        }
     }
 }
 
+struct OnboardRow: View {
+    var icon: String
+    var iconColor: Color
+    var headline: String
+    var bodyText: String
+    var position: Int
+    
+    let columns = [GridItem(.flexible())]
+    
+    var body: some View {
+        HStack(alignment: .center) {
+            Image(systemName: icon)
+                .foregroundColor(iconColor)
+                .frame(width: 40)
+                .font(.system(size: 35))
+                .padding(.trailing)
+            
+            VStack(alignment: .leading) {
+                Text(headline)
+                    .font(.headline)
+                
+                Text(bodyText)
+            }
+        }
+        .padding(.bottom)
+    }
+}
+
+struct OnboardButton: View {
+    @Binding var showContentView: Bool
+    
+    var body: some View {
+        HStack {
+            Spacer()
+            Button(action: { self.showContentView = true }) {
+                RoundedRectangle(cornerRadius: 10)
+                    .foregroundColor(.blue)
+                    .frame(height: 50)
+                    .overlay(
+                    Text("Continue")
+                        .foregroundColor(.white)
+                    )
+            }
+            
+            Spacer()
+        }
+    }
+    
+//    func writeUserDefaults() {
+//        let defaults = UserDefaults.standard
+//        defaults.setValue(true, forKey: "IsAppAlreadyLaunchedOnce")
+//    }
+}
+
 struct OnboardView_Previews: PreviewProvider {
     static var previews: some View {
         OnboardView()
--- a/LazyBear/Views/WelcomeView.swift	Sun Mar 21 19:56:24 2021 +0100
+++ b/LazyBear/Views/WelcomeView.swift	Sun Mar 21 19:56:48 2021 +0100
@@ -8,8 +8,56 @@
 import SwiftUI
 
 struct WelcomeView: View {
+    @State private var showingOnboardView = false
+    @State private var showProgressView = false
+    
     var body: some View {
-        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
+        if showingOnboardView {
+            OnboardView()
+        } else {
+            GeometryReader { geo in
+                VStack(alignment: .leading) {
+                    Spacer()
+                    Image("default")
+                        .resizable()
+                        .frame(width: geo.size.width * 0.2, height: geo.size.width * 0.2)
+                        .cornerRadius(25)
+                        .shadow(color: Color.black.opacity(0.2), radius: 10)
+                    
+                    Group {
+                        Text("Welcome to")
+                        Text("Lazybear")
+                            .foregroundColor(.blue)
+                            .offset(y: -15)
+                            .padding(.bottom, -15)
+                    }
+                    .font((.system(size: 50, weight: .black)))
+                            
+                    Text("Easily follow your stocks and the markets in real-time.")
+                    
+                    HStack {
+                        if self.showProgressView {
+                            Spacer()
+                            ProgressView()
+                            Spacer()
+                        }
+                    }
+                    .padding()
+                    .frame(height: 30)
+                    
+                    Spacer()
+                }
+                .padding(geo.size.width * 0.15)
+                .onAppear {
+                    DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
+                        self.showingOnboardView = true
+                    }
+                    DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
+                        self.showProgressView = true
+                    }
+                }
+            }
+        }
     }
 }