MainCoordinator.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. case .cart:
  23. showCartModule()
  24. default: EmptyView()
  25. }
  26. }
  27. // MARK: - Private methods
  28. private func showMainModule() -> some View {
  29. MainBuilder().build(
  30. with: .init(
  31. onProducts: { [weak self] in
  32. self?.currentRouter.push(Route.products)
  33. },
  34. onCart: { [weak self] in
  35. self?.currentRouter.push(Route.cart)
  36. }
  37. )
  38. )
  39. }
  40. private func showProductsModule() -> some View {
  41. ProductsBuilder().build(
  42. with: .init(
  43. onCart: { [weak self] in
  44. self?.currentRouter.push(Route.cart)
  45. }
  46. )
  47. )
  48. }
  49. private func showCartModule() -> some View {
  50. CartBuilder().build(
  51. with: .init(
  52. onProducts: { [weak self] in
  53. self?.currentRouter.push(Route.products)
  54. }
  55. )
  56. )
  57. }
  58. }