| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- //
- // 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 .product(let id):
- showProductModule(with: id)
- 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)
- },
- onProduct: { [weak self] id in
- self?.currentRouter.push(Route.product(id: id))
- },
- onCart: { [weak self] in
- self?.currentRouter.push(Route.cart)
- }
- )
- )
- }
- private func showProductsModule() -> some View {
- ProductsBuilder().build(
- with: .init(
- onProduct: { [weak self] in
- self?.currentRouter.push(Route.product(id: $0))
- },
- 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)
- }
- )
- )
- }
- private func showProductModule(with id: Int) -> some View {
- ProductBuilder().build(
- with: .init(id: id),
- output: .init(
- onProducts: { [weak self] in
- self?.currentRouter.push(Route.products)
- },
- onCart: { [weak self] in
- self?.currentRouter.push(Route.cart)
- }
- )
- )
- }
- }
|