65 lines
1.4 KiB
Swift
Executable File
65 lines
1.4 KiB
Swift
Executable File
// Copyright © 2025 VOID Software SA. All rights reserved.
|
|
|
|
import SwiftUI
|
|
import Swinject
|
|
import Combine
|
|
|
|
class AppStateManager: ObservableObject {
|
|
|
|
@Published var currentAppState: AppState?
|
|
@Published var path = NavigationPath()
|
|
|
|
static let isProduction = false
|
|
|
|
private var internalStack: [AppState] = []
|
|
var currentBottomMenuPosition: Int = 0
|
|
|
|
func navigateTo(state: AppState) {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
// If the requested state is already the current one, do nothing
|
|
if let currentState = self.currentAppState, currentState == state {
|
|
return
|
|
}
|
|
|
|
self.internalStack.append(state)
|
|
|
|
self.path.append(state)
|
|
self.currentAppState = state
|
|
|
|
}
|
|
}
|
|
|
|
func navigateBack() {
|
|
|
|
DispatchQueue.main.async {
|
|
guard !self.path.isEmpty else { return }
|
|
|
|
if self.path.count <= 1 {
|
|
return
|
|
}
|
|
|
|
self.path.removeLast()
|
|
_ = self.internalStack.popLast()
|
|
|
|
if self.internalStack.isEmpty {
|
|
self.currentAppState = self.internalStack.last
|
|
} else {
|
|
self.currentAppState = nil
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
func resetNavigation() {
|
|
|
|
DispatchQueue.main.async {
|
|
self.path = NavigationPath()
|
|
self.internalStack.removeAll()
|
|
self.currentAppState = nil
|
|
}
|
|
}
|
|
|
|
}
|