# HG changeset patch # User Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> # Date 1616353008 -3600 # Node ID 46dfb60e0874e5bb41f2da8348dc4ed34b640753 # Parent b481783c32c0c0f1aba04731f34d11e8384b6dea Implement WelcomeView diff -r b481783c32c0 -r 46dfb60e0874 LazyBear/ContentView.swift --- 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") } } diff -r b481783c32c0 -r 46dfb60e0874 LazyBear/LazyBear.xcdatamodeld/LazyBear.xcdatamodel/contents --- 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 @@ - - - - - - - - - - - - - - - + + + - - + \ No newline at end of file diff -r b481783c32c0 -r 46dfb60e0874 LazyBear/LazyBearApp.swift --- 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 } } } diff -r b481783c32c0 -r 46dfb60e0874 LazyBear/Persistence.swift --- 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 { diff -r b481783c32c0 -r 46dfb60e0874 LazyBear/Views/OnboardView.swift --- 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() diff -r b481783c32c0 -r 46dfb60e0874 LazyBear/Views/WelcomeView.swift --- 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 + } + } + } + } } }