| 1 |
//
|
|
| 2 |
// RouteComposer
|
|
| 3 |
// ChildCoordinator.swift
|
|
| 4 |
// https://github.com/ekazaev/route-composer
|
|
| 5 |
//
|
|
| 6 |
// Created by Eugene Kazaev in 2018-2022.
|
|
| 7 |
// Distributed under the MIT license.
|
|
| 8 |
//
|
|
| 9 |
// Become a sponsor:
|
|
| 10 |
// https://github.com/sponsors/ekazaev
|
|
| 11 |
//
|
|
| 12 |
|
|
| 13 |
import Foundation
|
|
| 14 |
import UIKit
|
|
| 15 |
|
|
| 16 |
/// Helps to build a child view controller stack
|
|
| 17 |
public struct ChildCoordinator {
|
|
| 18 |
|
|
| 19 |
// MARK: Properties
|
|
| 20 |
|
|
| 21 |
var childFactories: [(factory: PostponedIntegrationFactory, context: AnyContext)]
|
|
| 22 |
|
|
| 23 |
/// Returns `true` if the coordinator contains child factories to build
|
|
| 24 |
public var isEmpty: Bool {
|
42x |
| 25 |
childFactories.isEmpty
|
42x |
| 26 |
}
|
42x |
| 27 |
|
|
| 28 |
// MARK: Methods
|
|
| 29 |
|
|
| 30 |
init(childFactories: [(factory: PostponedIntegrationFactory, context: AnyContext)]) {
|
60x |
| 31 |
self.childFactories = childFactories
|
60x |
| 32 |
}
|
60x |
| 33 |
|
|
| 34 |
/// Builds child view controller stack with the context instance provided.
|
|
| 35 |
///
|
|
| 36 |
/// - Parameters:
|
|
| 37 |
/// - existingViewControllers: Current view controller stack of the container.
|
|
| 38 |
/// - Returns: Built child view controller stack
|
|
| 39 |
public func build(integrating existingViewControllers: [UIViewController] = []) throws -> [UIViewController] {
|
43x |
| 40 |
var childrenViewControllers = existingViewControllers
|
43x |
| 41 |
for factory in childFactories {
|
62x |
| 42 |
try factory.factory.build(with: factory.context, in: &childrenViewControllers)
|
62x |
| 43 |
}
|
62x |
| 44 |
return childrenViewControllers
|
43x |
| 45 |
}
|
43x |
| 46 |
|
|
| 47 |
}
|
|