Skip to content

Commit

Permalink
Merge branch 'main' into readme-2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdrobne authored Sep 21, 2023
2 parents 1a7950b + fb9a376 commit dbe76c5
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 9 deletions.
7 changes: 5 additions & 2 deletions Sources/SwiftUICoordinator/Coordinator/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ public extension Coordinator {
// MARK: - Public methods

func add(child: Coordinator) {
if !childCoordinators.contains(where: { $0 === child }) {
childCoordinators.append(child)
guard !childCoordinators.contains(where: { $0 === child }) else {
Logger.coordinator.warning("Attempted to add a coordinator that is already a child.")
return
}

childCoordinators.append(child)
}

func remove(coordinator: Coordinator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import Foundation

/// A protocol that defines coordinator actions.
public protocol CoordinatorAction {}

/// Essential actions that can be performed by coordinators.
public enum Action: CoordinatorAction {
case done(Any)
case cancel(Any)
Expand Down
2 changes: 2 additions & 0 deletions Sources/SwiftUICoordinator/Logger+Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ extension Logger {

/// Logs related to deep links.
static let deepLink = Logger(subsystem: subsystem, category: "deep_link")
/// Logs related to coordinator management and operations.
static let coordinator = Logger(subsystem: subsystem, category: "coordinator")
}
17 changes: 13 additions & 4 deletions Sources/SwiftUICoordinator/Routing/NavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class NavigationController: UINavigationController {

// MARK: - Internal Properties

/// The collection of registered transition objects.
private(set) var transitions = [Transition]()

// MARK: - Initialization
Expand All @@ -32,10 +33,16 @@ public class NavigationController: UINavigationController {

// MARK: - Public methods

/// Registers a single `Transition` for use in navigation animations.
///
/// - Parameter transition: The `Transition` to be registered.
public func register(_ transition: Transition) {
transitions.append(transition)
}

/// Registers multiple `Transition` objects for use in navigation animations.
///
/// - Parameter transitions: An array of `Transition` objects to be registered.
public func register(_ transitions: [Transition]) {
self.transitions += transitions
}
Expand All @@ -44,10 +51,12 @@ public class NavigationController: UINavigationController {
// MARK: - UINavigationControllerDelegate

extension NavigationController: UINavigationControllerDelegate {
public func navigationController(_ navigationController: UINavigationController,
animationControllerFor operation: UINavigationController.Operation,
from fromVC: UIViewController,
to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
public func navigationController(
_ navigationController: UINavigationController,
animationControllerFor operation: UINavigationController.Operation,
from fromVC: UIViewController,
to toVC: UIViewController
) -> UIViewControllerAnimatedTransitioning? {

for transition in transitions {
guard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

@MainActor
public protocol NavigationRoute {
/// This title can be used to set the navigation bar title when the route is shown.
/// Use this title to set the navigation bar title when the route is displayed.
var title: String? { get }
/// A property that provides the info about the appearance and styling of a route in the navigation system.
var appearance: RouteAppearance? { get }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class RouteHostingController<Content: View>: UIHostingController<Content>

// MARK: - Public properties

/// The navigation route associated with this hosting controller.
public let route: NavigationRoute

// MARK: - Initialization
Expand Down
6 changes: 6 additions & 0 deletions Sources/SwiftUICoordinator/Routing/RouterViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ import SwiftUI

@MainActor
public protocol RouterViewFactory {
/// The type of SwiftUI view to be created for a given route.
associatedtype V: View
/// The type of navigation route for which views will be created.
associatedtype Route: NavigationRoute

/// Creates a SwiftUI view for the specified navigation route.
///
/// - Parameter `route`: The navigation route for which the view should be created.
/// - Returns: A SwiftUI view (`V`) associated with the provided route.
@ViewBuilder
func view(for route: Route) -> V
}
Expand Down
14 changes: 13 additions & 1 deletion Sources/SwiftUICoordinator/Transition/Transition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import SwiftUI

public typealias NavigationOperation = UINavigationController.Operation

/// Determines if the transition is eligible for a given pair of source and destination routes and the navigation operation.
///
/// - Parameters:
/// - fromRoute: The source `NavigationRoute` for the transition.
/// - toRoute: The destination `NavigationRoute` for the transition.
/// - operation: The `NavigationOperation` describing the navigation action (push or pop).
///
/// - Returns: `true` if the transition is eligible; otherwise, `false`.
public protocol Transition: UIViewControllerAnimatedTransitioning {
func isEligible(from fromRoute: NavigationRoute, to toRoute: NavigationRoute, operation: NavigationOperation) -> Bool
func isEligible(
from fromRoute: NavigationRoute,
to toRoute: NavigationRoute,
operation: NavigationOperation
) -> Bool
}
1 change: 1 addition & 0 deletions Sources/SwiftUICoordinator/View+Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import SwiftUI

extension View {

@ViewBuilder
func ifLet<T, Content: View>(_ value: T?, modifier: (Self, T) -> Content) -> some View {
if let value = value {
Expand Down

0 comments on commit dbe76c5

Please sign in to comment.