[Library] Coordination library (#15)

This PR contains the work done to implement the necessary protocols and router to implement the Coordinators pattern in the app.

Reviewed-on: rock-n-code/app-reviews#15
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #15.
This commit is contained in:
2024-03-21 16:40:30 +00:00
committed by javier
parent 394245dd29
commit 60cab50c1e
11 changed files with 534 additions and 0 deletions
@@ -0,0 +1,36 @@
//
// OtherCoordinator.swift
// ReviewsCoordinationTest
//
// Created by Javier Cicchelli on 21/03/2024.
// Copyright © 2024 Röck+Cöde. All rights reserved.
//
import ReviewsCoordinationKit
final class OtherCoordinator: Coordinator {
// MARK: Constants
let router: Router
// MARK: Properties
var children: [Coordinator] = []
// MARK: Initialisers
init(router: Router) {
self.router = router
}
// MARK: Functions
func present(
animated: Bool,
onDismiss: (() -> Void)?
) {
router.present(
OtherViewController(),
animated: animated,
onDismiss: onDismiss
)
}
}
@@ -0,0 +1,36 @@
//
// SomeCoordinator.swift
// ReviewsCoordinationTest
//
// Created by Javier Cicchelli on 21/03/2024.
// Copyright © 2024 Röck+Cöde. All rights reserved.
//
import ReviewsCoordinationKit
final class SomeCoordinator: Coordinator {
// MARK: Constants
let router: Router
// MARK: Properties
var children: [Coordinator] = []
// MARK: Initialisers
init(router: Router) {
self.router = router
}
// MARK: Functions
func present(
animated: Bool,
onDismiss: (() -> Void)?
) {
router.present(
SomeViewController(),
animated: animated,
onDismiss: onDismiss
)
}
}
@@ -0,0 +1,46 @@
//
// SpyRouter.swift
// ReviewsCoordinationTest
//
// Created by Javier Cicchelli on 21/03/2024.
// Copyright © 2024 Röck+Cöde. All rights reserved.
//
import ReviewsCoordinationKit
import UIKit
final class SpyRouter: Router {
// MARK: Properties
var animated: Bool?
var onDismiss: OnDismissClosure?
var state: State = .initialised
var viewController: UIViewController?
// MARK: Functions
func present(
_ viewController: UIViewController,
animated: Bool,
onDismiss: OnDismissClosure?
) {
self.viewController = viewController
self.animated = animated
self.onDismiss = onDismiss
self.state = .presented
}
func dismiss(animated: Bool) {
self.animated = animated
self.state = .dismissed
}
}
// MARK: - Enumerations
extension SpyRouter {
enum State {
case initialised
case presented
case dismissed
}
}
@@ -0,0 +1,12 @@
//
// TestViewControllers.swift
// ReviewsCoordinationTests
//
// Created by Javier Cicchelli on 21/03/2024.
// Copyright © 2024 Röck+Cöde. All rights reserved.
//
import UIKit
final class SomeViewController: UIViewController {}
final class OtherViewController: UIViewController {}