1 |
//
|
|
2 |
// RouteComposer
|
|
3 |
// StepChainAssembly.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 |
/// Helper class to build a chain of steps. Can not be used directly.
|
|
17 |
public struct StepChainAssembly<ViewController: UIViewController, Context> {
|
|
18 |
|
|
19 |
// MARK: Properties
|
|
20 |
|
|
21 |
let previousSteps: [RoutingStep]
|
|
22 |
|
|
23 |
// MARK: Methods
|
|
24 |
|
|
25 |
init(previousSteps: [RoutingStep]) {
|
117x |
26 |
self.previousSteps = previousSteps
|
117x |
27 |
}
|
117x |
28 |
|
|
29 |
/// Adds a single step to the chain
|
|
30 |
///
|
|
31 |
/// - Parameter previousStep: The instance of `StepWithActionAssemblable`
|
|
32 |
public func from(_ step: ActionToStepIntegrator<some UIViewController, Context>) -> ActionConnectingAssembly<ViewController, Context> {
|
3x |
33 |
ActionConnectingAssembly<ViewController, Context>(stepToFullFill: step, previousSteps: previousSteps)
|
3x |
34 |
}
|
3x |
35 |
|
|
36 |
/// Adds a `DestinationStep` to the chain. This step will be the last one in the chain.
|
|
37 |
///
|
|
38 |
/// - Parameter previousStep: The instance of `DestinationStep`
|
|
39 |
public func from(_ step: DestinationStep<some UIViewController, Context>) -> LastStepInChainAssembly<ViewController, Context> {
|
110x |
40 |
var previousSteps = previousSteps
|
110x |
41 |
previousSteps.append(step)
|
110x |
42 |
return LastStepInChainAssembly<ViewController, Context>(previousSteps: previousSteps)
|
110x |
43 |
}
|
110x |
44 |
|
|
45 |
/// Assembles all the provided settings.
|
|
46 |
///
|
|
47 |
/// - Parameter step: An instance of `DestinationStep` to start to build a current step from.
|
|
48 |
/// - Returns: An instance of `DestinationStep` with all the provided settings inside.
|
|
49 |
public func assemble(from step: DestinationStep<some UIViewController, Context>) -> DestinationStep<ViewController, Context> {
|
4x |
50 |
var previousSteps = previousSteps
|
4x |
51 |
previousSteps.append(step)
|
4x |
52 |
return LastStepInChainAssembly<ViewController, Context>(previousSteps: previousSteps).assemble()
|
4x |
53 |
}
|
4x |
54 |
|
|
55 |
}
|
|