[Framework] Feed Item coordinator (#17)

This PR contains the work done to implement the `FeedItemCoordinator` coordinator in the `Feed` framework.

Reviewed-on: rock-n-code/app-reviews#17
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 #17.
This commit is contained in:
2024-03-21 22:56:38 +00:00
committed by javier
parent 9a5c385903
commit d19c1c15d1
13 changed files with 287 additions and 63 deletions
@@ -0,0 +1,103 @@
//
// SheetRouter.swift
// ReviewsCoordinationKit
//
// Created by Javier Cicchelli on 21/03/2024.
// Copyright © 2024 Röck+Cöde. All rights reserved.
//
import ReviewsUIKit
import UIKit
public class SheetRouter: BaseNavigationRouter {
// MARK: Properties
public unowned let parentViewController: UIViewController
// MARK: Initialisers
public init(parentViewController: UIViewController) {
self.parentViewController = parentViewController
super.init(navigationController: .init())
}
}
// MARK: - Router
extension SheetRouter: Router {
// MARK: Functions
public func present(
_ viewController: UIViewController,
animated: Bool,
onDismiss: Router.OnDismissClosure?
) {
onDismissForViewController[viewController] = onDismiss
if navigationController.viewControllers.isEmpty {
presentModally(
viewController,
animated: animated
)
} else {
navigationController.pushViewController(
viewController,
animated: animated
)
}
}
public func dismiss(animated: Bool) {
guard let firstViewController = navigationController.viewControllers.first else {
return
}
performOnDismiss(for: firstViewController)
parentViewController.dismiss(animated: animated)
}
}
// MARK: - Helpers
private extension SheetRouter {
// MARK: Actions
@objc func onCancelPressed() {
guard let firstViewController = navigationController.viewControllers.first else {
return
}
dismiss(animated: true)
performOnDismiss(for: firstViewController)
}
// MARK: Functions
func presentModally(
_ viewController: UIViewController,
animated: Bool
) {
viewController.navigationItem.rightBarButtonItem = UIBarButtonItem(
image: .Icon.close,
style: .plain,
target: self,
action: #selector(onCancelPressed)
)
if #available(iOS 15.0, *) {
navigationController.sheetPresentationController?.detents = [.medium(), .large()]
}
navigationController.setViewControllers(
[viewController],
animated: false
)
parentViewController.present(
navigationController,
animated: animated
)
}
}
+1
View File
@@ -25,6 +25,7 @@ let package = Package(
name: .Target.coordination.kit,
dependencies: [
.byName(name: .Target.foundation.kit),
.byName(name: .Target.ui.kit),
],
path: "Coordination/Kit"
),
@@ -19,6 +19,7 @@ public extension String {
public static let star4 = "4.circle"
public static let star5 = "5.circle"
static let close = "xmark.circle.fill"
static let filter = "camera.filters"
static let questionMark = "questionmark.circle.fill"
static let star = "star"
@@ -1,5 +1,5 @@
//
// UIImage+ICons.swift
// UIImage+Icons.swift
// ReviewsUIKit
//
// Created by Javier Cicchelli on 20/03/2024.
@@ -12,6 +12,7 @@ public extension UIImage {
enum Icon {
// MARK: Constants
public static let close = UIImage(systemName: .Icon.close)
public static let filter = UIImage(systemName: .Icon.filter)
public static let star = UIImage(systemName: .Icon.star)