summaryrefslogtreecommitdiffhomepage
path: root/ios/Routing/Router/ApplicationRouterDelegate.swift
blob: 3f8426bc2403a241dc63e5ea09325d1519d64f53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
//  ApplicationRouterDelegate.swift
//  MullvadVPN
//
//  Created by pronebird on 17/08/2023.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import Foundation

/**
 Application router delegate
 */
public protocol ApplicationRouterDelegate<RouteType>: AnyObject, Sendable {
    associatedtype RouteType: AppRouteProtocol

    /**
     Delegate should present the route and pass corresponding `Coordinator` upon completion.
     */
    func applicationRouter(
        _ router: ApplicationRouter<RouteType>,
        presentWithContext context: RoutePresentationContext<RouteType>,
        animated: Bool,
        completion: @escaping @Sendable (Coordinator) -> Void
    )

    /**
     Delegate should dismiss the route.
     */
    func applicationRouter(
        _ router: ApplicationRouter<RouteType>,
        dismissWithContext context: RouteDismissalContext<RouteType>,
        completion: @escaping @Sendable () -> Void
    )

    /**
     Delegate may reconsider if route presentation is still needed.
    
     Return `true` to proceed with presenation, otherwise `false` to prevent it.
     */
    func applicationRouter(_ router: ApplicationRouter<RouteType>, shouldPresent route: RouteType) -> Bool

    /**
     Delegate may reconsider if route dismissal should be done.
    
     Return `true` to proceed with dismissal, otherwise `false` to prevent it.
     */
    func applicationRouter(
        _ router: ApplicationRouter<RouteType>,
        shouldDismissWithContext context: RouteDismissalContext<RouteType>
    ) -> Bool

    /**
     Delegate should handle sub-navigation for routes supporting it then call completion to tell
     router when it's done.
     */
    func applicationRouter(
        _ router: ApplicationRouter<RouteType>,
        handleSubNavigationWithContext context: RouteSubnavigationContext<RouteType>,
        completion: @escaping @Sendable @MainActor () -> Void
    )
}