ApplicationCoordinator.swift 834 B

1234567891011121314151617181920212223242526272829303132333435
  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. func run() -> some View {
  11. runMainFlow()
  12. }
  13. func buildDestination(_ route: Route) -> some View {
  14. guard let coordinator = currentCoordinator as? MainCoordinator else {
  15. fatalError("Invalid coordinator type")
  16. }
  17. return coordinator.buildDestination(route)
  18. }
  19. // MARK: - Private methods
  20. private func runMainFlow() -> some View {
  21. let coordinator = MainCoordinator(router: self.currentRouter)
  22. addChild(coordinator)
  23. coordinator.finishFlow = { [weak self] in
  24. self?.removeChild(coordinator)
  25. }
  26. return coordinator.run()
  27. }
  28. }