MainCoordinator.swift 922 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // MainCoordinator.swift
  3. // SUIExamples
  4. //
  5. // Created by Pavel Yurchenko on 28.11.2024.
  6. //
  7. import CoordinatorSUI
  8. import SwiftUI
  9. final class MainCoordinator: BaseCoordinator {
  10. init(router: Router) {
  11. super.init()
  12. self.currentRouter = router
  13. }
  14. func run() -> some View {
  15. showMainModule()
  16. }
  17. @ViewBuilder
  18. func buildDestination(_ route: Route) -> some View {
  19. switch route {
  20. case .products:
  21. showProductsModule()
  22. default: EmptyView()
  23. }
  24. }
  25. // MARK: - Private methods
  26. private func showMainModule() -> some View {
  27. MainBuilder().build(
  28. with: .init(
  29. onProducts: { [weak self] in
  30. self?.currentRouter.push(Route.products)
  31. })
  32. )
  33. }
  34. private func showProductsModule() -> some View {
  35. ProductsBuilder().build(with: .init())
  36. }
  37. }