This PR contains the work done to define the `Coordinator` and the `Router` public protocols, and also implemented a few concrete router implementations tailored for the **UIKit** framework. To provide further details about the work done: - [x] define a new, dedicated `Coordinator` target in the `Package` file; - [x] define the `Coordinator` and the `Router` public protocols used to implement the coordinator pattern; - [x] implemented some **UIKit** specific routers to use on the **iOS** platform: `ModalNavigationRouter`, `PushNavigationRouter` and the `WindowRouter` concrete routers. Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Reviewed-on: #2
44 lines
1006 B
Swift
44 lines
1006 B
Swift
//
|
|
// WindowRouter.swift
|
|
// Coordinator
|
|
//
|
|
// Created by Javier Cicchelli on 11/04/2023.
|
|
// Copyright © 2023 Röck+Cöde. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
/// This class is responsible for populating the window of an application.
|
|
public class WindowRouter: Router {
|
|
|
|
// MARK: Properties
|
|
|
|
/// The window to set manually with a `UIViewController` view controller instance.
|
|
private let window: UIWindow?
|
|
|
|
// MARK: Initialisers
|
|
|
|
/// Initialise this router.
|
|
/// - Parameter window: A `UIWindow` window instance to be set manually.
|
|
public init(window: UIWindow?) {
|
|
self.window = window
|
|
}
|
|
|
|
// MARK: Functions
|
|
|
|
public func present(
|
|
_ viewController: UIViewController,
|
|
animated: Bool,
|
|
onDismiss: OnDismissedClosure?
|
|
) {
|
|
window?.rootViewController = viewController
|
|
|
|
window?.makeKeyAndVisible()
|
|
}
|
|
|
|
public func dismiss(animated: Bool) {
|
|
// Nothing to do here...
|
|
}
|
|
|
|
}
|