Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AppCoordinator: ObservableObject {
- enum AuthenticationStatus {
- case loggedIn
- case firstTimeUser
- }
- @Published var currentScreen: Screen?
- // Использую ленивые свойства для создания координаторов
- lazy var loginCoordinator: LoginCoordinator = {
- let coordinator = LoginCoordinator()
- coordinator.parentCoordinator = self
- return coordinator
- }()
- lazy var registrationCoordinator: RegistrationCoordinator = {
- let coordinator = RegistrationCoordinator()
- coordinator.parentCoordinator = self
- return coordinator
- }()
- lazy var mainCoordinator: MainScreenCoordinator = {
- let coordinator = MainScreenCoordinator()
- coordinator.parentCoordinator = self
- return coordinator
- }()
- init() {
- checkAuthenticationStatus()
- NotificationCenter.default.addObserver(self, selector: #selector(handleShowRegistration), name: NSNotification.Name("ShowRegistration"), object: nil)
- }
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
- @objc func handleShowRegistration() {
- showRegistration()
- }
- private func checkAuthenticationStatus() {
- // TODO: логика
- let status: AuthenticationStatus = .firstTimeUser
- setCurrentScreen(for: status)
- }
- private func setCurrentScreen(for status: AuthenticationStatus) {
- switch status {
- case .loggedIn:
- currentScreen = .main
- case .firstTimeUser:
- currentScreen = .authenticationChoice
- }
- }
- func showLogin() {
- currentScreen = .login
- }
- func showRegistration() {
- currentScreen = .registration
- }
- func showMain() {
- currentScreen = .main
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement