Slather logo

Coverage for "DismissalMethodProvidingContextTask.swift" : 100.00%

(6 of 6 relevant lines covered)

RouteComposer/Classes/Extra/DismissalMethodProvidingContextTask.swift

1
//
2
// RouteComposer
3
// DismissalMethodProvidingContextTask.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
/// `DismissalMethodProvidingContextTask` allows to provide the way to dismiss the `UIViewController` using a preset configuration.
17
/// The `UIViewController` should conform to `Dismissible` protocol and call `Dismissible.dismissViewController(...)` method
18
/// when it needs to be dismissed to trigger the dismissal process implemented in `DismissalMethodProvidingContextTask.init(...)`
19
/// constructor.
20
public struct DismissalMethodProvidingContextTask<VC: Dismissible, C>: ContextTask {
21
22
    // MARK: Properties
23
24
    let dismissalBlock: (_: VC.DismissalTargetContext, _: Bool, _: ((_: RoutingResult) -> Void)?) -> Void
25
26
    // MARK: Methods
27
28
    /// Constructor
29
    ///
30
    /// - Parameter dismissalBlock: Block that will trigger the dismissal process when `Dismissible` `UIViewController` calls
31
    ///    `Dismissible.dismissViewController(...)` method.
32
    public init(dismissalBlock: @escaping (_: VC.DismissalTargetContext, _: Bool, _: ((_: RoutingResult) -> Void)?) -> Void) {
13x
33
        self.dismissalBlock = dismissalBlock
13x
34
    }
13x
35
36
    public func perform(on viewController: VC, with context: C) throws {
12x
37
        viewController.dismissalBlock = dismissalBlock
12x
38
    }
12x
39
40
}