1 |
//
|
|
2 |
// RouteComposer
|
|
3 |
// Router+Destination.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 |
public extension Router {
|
|
17 |
|
|
18 |
// MARK: Navigation methods for the Destination instance
|
|
19 |
|
|
20 |
/// Navigates the application to the view controller configured in `Destination` with the `Context` provided.
|
|
21 |
///
|
|
22 |
/// - Parameters:
|
|
23 |
/// - destination: `Destination` instance.
|
|
24 |
/// - animated: if true - the navigation should be animated where it is possible.
|
|
25 |
/// - completion: completion block.
|
|
26 |
func navigate(to destination: Destination<some UIViewController, some Any>, animated: Bool = true, completion: ((_: RoutingResult) -> Void)? = nil) throws {
|
26x |
27 |
try navigate(to: destination.step, with: destination.context, animated: animated, completion: completion)
|
26x |
28 |
}
|
26x |
29 |
|
|
30 |
/// Navigates the application to the view controller configured in `Destination` with the `Context` provided.
|
|
31 |
/// Method does not throw errors, but propagates them to the completion block.
|
|
32 |
///
|
|
33 |
/// - Parameters:
|
|
34 |
/// - destination: `Destination` instance.
|
|
35 |
/// - animated: if true - the navigation should be animated where it is possible.
|
|
36 |
/// - completion: completion block.
|
|
37 |
func commitNavigation(to destination: Destination<some UIViewController, some Any>, animated: Bool = true, completion: ((_: RoutingResult) -> Void)? = nil) {
|
2x |
38 |
do {
|
2x |
39 |
try navigate(to: destination, animated: animated, completion: completion)
|
2x |
40 |
} catch {
|
2x |
41 |
completion?(.failure(error))
|
1x |
42 |
}
|
2x |
43 |
}
|
2x |
44 |
|
|
45 |
}
|
|