| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- //
- // MainCoordinator.swift
- // SUIExamples
- //
- // Created by Pavel Yurchenko on 28.11.2024.
- //
- import CoordinatorSUI
- import SwiftUI
- final class MainCoordinator: BaseCoordinator {
- init(router: Router) {
- super.init()
- self.currentRouter = router
- }
- func run() -> some View {
- showMainModule()
- }
- @ViewBuilder
- func buildDestination(_ route: Route) -> some View {
- switch route {
- case .products:
- showProductsModule()
- case .cart:
- showCartModule()
- default: EmptyView()
- }
- }
- // MARK: - Private methods
- private func showMainModule() -> some View {
- MainBuilder().build(
- with: .init(
- onProducts: { [weak self] in
- self?.currentRouter.push(Route.products)
- },
- onCart: { [weak self] in
- self?.currentRouter.push(Route.cart)
- }
- )
- )
- }
- private func showProductsModule() -> some View {
- ProductsBuilder().build(
- with: .init(
- onCart: { [weak self] in
- self?.currentRouter.push(Route.cart)
- }
- )
- )
- }
- private func showCartModule() -> some View {
- CartBuilder().build(
- with: .init(
- onProducts: { [weak self] in
- self?.currentRouter.push(Route.products)
- }
- )
- )
- }
- }
|