Skip to content

Commit

Permalink
add app state manager
Browse files Browse the repository at this point in the history
  • Loading branch information
janndriessen committed Jun 27, 2021
1 parent 4beeecc commit 809a74a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/eazy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
6911B7062688729F00694D60 /* StartScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6911B7052688729F00694D60 /* StartScreen.swift */; };
6911B70A268876C200694D60 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6911B709268876C200694D60 /* AppState.swift */; };
6943C96C2684857600A120D6 /* DashboardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6943C96B2684857600A120D6 /* DashboardView.swift */; };
6943C96E2684859C00A120D6 /* EazyColors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6943C96D2684859C00A120D6 /* EazyColors.swift */; };
6976D2852681D60E00E50002 /* eazyApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6976D2842681D60E00E50002 /* eazyApp.swift */; };
Expand All @@ -18,6 +19,7 @@

/* Begin PBXFileReference section */
6911B7052688729F00694D60 /* StartScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartScreen.swift; sourceTree = "<group>"; };
6911B709268876C200694D60 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = "<group>"; };
6943C96B2684857600A120D6 /* DashboardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardView.swift; sourceTree = "<group>"; };
6943C96D2684859C00A120D6 /* EazyColors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EazyColors.swift; sourceTree = "<group>"; };
6976D2812681D60E00E50002 /* eazy.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = eazy.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -58,6 +60,7 @@
6976D2832681D60E00E50002 /* eazy */ = {
isa = PBXGroup;
children = (
6911B709268876C200694D60 /* AppState.swift */,
6943C96D2684859C00A120D6 /* EazyColors.swift */,
6976D2842681D60E00E50002 /* eazyApp.swift */,
6976D2862681D60E00E50002 /* ContentView.swift */,
Expand Down Expand Up @@ -150,6 +153,7 @@
6976D2872681D60E00E50002 /* ContentView.swift in Sources */,
6943C96C2684857600A120D6 /* DashboardView.swift in Sources */,
6911B7062688729F00694D60 /* StartScreen.swift in Sources */,
6911B70A268876C200694D60 /* AppState.swift in Sources */,
6943C96E2684859C00A120D6 /* EazyColors.swift in Sources */,
6976D2852681D60E00E50002 /* eazyApp.swift in Sources */,
);
Expand Down
28 changes: 28 additions & 0 deletions app/eazy/AppState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// AppState.swift
// eazy
//
// Created by Jann Driessen on 27.06.21.
//

import Foundation

enum AppState {
case loading
case main
case onboarding
}

class AppStateManager: ObservableObject {
@Published var appState: AppState = .loading

init() {}

func startOnboarding() {
appState = .onboarding
}

func signedIn() {
appState = .main
}
}
31 changes: 29 additions & 2 deletions app/eazy/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,39 @@
import SwiftUI

struct ContentView: View {
@StateObject private var appStateManager = AppStateManager()

var body: some View {
Text("hello world 🕶")
.padding()
switch appStateManager.appState {
case .loading:
StartScreen()
.transition(.opacity)
.onAppear {
showOnboarding()
}
case .main:
DashboardView()
.animation(.easeIn)
.transition(.opacity)
.environmentObject(appStateManager)
case .onboarding:
DashboardView()
.animation(.easeIn)
.transition(.opacity)
.environmentObject(appStateManager)
}
}

private func showOnboarding() {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
withAnimation {
self.appStateManager.appState = .onboarding
}
}
}
}


struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
Expand Down
2 changes: 1 addition & 1 deletion app/eazy/StartScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct StartScreen: View {
VStack {
Spacer()
Text("eazy.finance 🕶")
.font(.system(size: 46, design: .rounded).bold())
.font(.system(size: 44, design: .rounded).bold())
.padding()
Spacer()
Text("Powered by")
Expand Down

0 comments on commit 809a74a

Please sign in to comment.