ApplicationCoordinator.swift 967 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // ApplicationCoordinator.swift
  3. // SUIExamples
  4. //
  5. // Created by Pavel Yurchenko on 28.11.2024.
  6. //
  7. import CoordinatorSUI
  8. import SwiftUI
  9. final class ApplicationCoordinator: BaseCoordinator {
  10. static var rootRouter = Router()
  11. override init() {
  12. super.init()
  13. self.currentRouter = Self.rootRouter
  14. }
  15. func run() -> some View {
  16. runMainFlow()
  17. }
  18. func buildDestination(_ route: Route) -> some View {
  19. guard let coordinator = currentCoordinator as? MainCoordinator else {
  20. fatalError("Invalid coordinator type")
  21. }
  22. return coordinator.buildDestination(route)
  23. }
  24. // MARK: - Private methods
  25. private func runMainFlow() -> some View {
  26. let coordinator = MainCoordinator(router: self.currentRouter)
  27. addChild(coordinator)
  28. coordinator.finishFlow = { [weak self] in
  29. self?.removeChild(coordinator)
  30. }
  31. return coordinator.run()
  32. }
  33. }