| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- //
- // 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()
- case .feedback:
- showFeedbackModule()
- default:
- fatalError("This should not happen!")
- }
- }
- // 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)
- },
- onFeedback: { [weak self] in
- self?.currentRouter.push(Route.feedback)
- }
- )
- )
- }
- 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)
- }
- )
- )
- }
- private func showFeedbackModule() -> some View {
- FeedbackBuilder().build(with: .init())
- }
- }
|