medmap-ios/medmap/medmapApp.swift
Ricardo Araújo 7ffbe04e37 login fix
2026-09-15 16:11:48 +01:00

115 lines
3.1 KiB
Swift

//
// medmapApp.swift
// medmap
//
// Created by Ricardo Araujo on 26/08/2026.
//
import SwiftUI
import SwiftData
@main
struct medmapApp: App {
@StateObject var appStateManager: AppStateManager = DIContainer.shared.resolve()
@Environment(\.scenePhase) private var scenePhase
var sharedModelContainer: ModelContainer = {
let schema = Schema([
Item.self,
])
let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
do {
return try ModelContainer(for: schema, configurations: [modelConfiguration])
} catch {
fatalError("Could not create ModelContainer: \(error)")
}
}()
var body: some Scene {
WindowGroup {
createNavigationStack(
SplashScreenView(viewModel: SplashScreenViewModel())
.environmentObject(appStateManager))
}
.onChange(of: scenePhase) { oldPhase, newPhase in
handleScenePhaseChange(from: oldPhase, to: newPhase)
}
}
private func handleScenePhaseChange(from oldPhase: ScenePhase, to newPhase: ScenePhase) {
switch newPhase {
case .active:
print("🟢 App became active")
case .inactive:
print("🟡 App became inactive")
// App is transitioning (e.g., notification center pulled down)
case .background:
print("🔴 App entered background")
handleAppEnteredBackground()
@unknown default:
break
}
}
private func handleAppEnteredBackground() {
// Runs when app enters background
// Example: Save state, pause operations
}
func createNavigationStack<V: View>(_ view: V) -> some View {
return AnyView(NavigationStack(path: $appStateManager.path) {
view
.navigationDestination(for: AppState.self) { destination in
switch destination {
case .splashScreen:
SplashScreenView(viewModel: SplashScreenViewModel())
.navigationBarHidden(true)
.transition(.move(edge: .bottom))
.animation(.easeInOut, value: 10)
case .login:
LoginView()
.navigationBarHidden(true)
.transition(.opacity)
.animation(.easeInOut, value: 10)
case .signup:
SignupView()
.navigationBarHidden(true)
.transition(.opacity)
.animation(.easeInOut, value: 10)
case .dashboard:
DashboardView()
.navigationBarHidden(true)
.transition(.opacity)
.animation(.easeInOut, value: 10)
}
}
})
}
}