|
|
@@ -0,0 +1,69 @@
|
|
|
+//
|
|
|
+// ModalProductsCoordinator.swift
|
|
|
+// CoordinatorSUIExamples
|
|
|
+//
|
|
|
+// Created by Pavel Yurchenko on 03.12.2024.
|
|
|
+//
|
|
|
+
|
|
|
+import CoordinatorSUI
|
|
|
+import SwiftUI
|
|
|
+
|
|
|
+final class ModalProductsCoordinator: BaseCoordinator {
|
|
|
+
|
|
|
+ func run() -> some View
|
|
|
+ {
|
|
|
+ showProductsModule()
|
|
|
+ }
|
|
|
+
|
|
|
+ @ViewBuilder
|
|
|
+ func buildDestination(_ route: Route) -> some View {
|
|
|
+ switch route {
|
|
|
+ case .product(let id):
|
|
|
+ showProductModule(with: id)
|
|
|
+ default:
|
|
|
+ fatalError("This should not happen!")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: - Private methods
|
|
|
+
|
|
|
+ private func showProductsModule() -> some View {
|
|
|
+ ProductsBuilder().build(
|
|
|
+ with: .init(
|
|
|
+ onProduct: { [weak self] in
|
|
|
+ self?.currentRouter.push(Route.product(id: $0))
|
|
|
+ }
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ private func showProductModule(with id: Int) -> some View {
|
|
|
+ ProductBuilder().build(
|
|
|
+ with: .init(id: id),
|
|
|
+ output: .init()
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - View
|
|
|
+
|
|
|
+struct ModalProductsNavigationView: View {
|
|
|
+
|
|
|
+ let coordinator: ModalProductsCoordinator
|
|
|
+ @StateObject var router: Router
|
|
|
+
|
|
|
+ var body: some View {
|
|
|
+ NavigationStack(path: $router.path) {
|
|
|
+ coordinator.run()
|
|
|
+ .navigationDestination(
|
|
|
+ for: Route.self,
|
|
|
+ destination: coordinator.buildDestination
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ViewBuilder
|
|
|
+ static func build(with coordinator: ModalProductsCoordinator) -> some View {
|
|
|
+ ModalProductsNavigationView(coordinator: coordinator, router: coordinator.currentRouter)
|
|
|
+ }
|
|
|
+}
|