Skip to content

Commit

Permalink
Add code docs to the navigation controller and associated objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdrobne committed Nov 7, 2023
1 parent e811816 commit 16c8921
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

import SwiftUI

/// A delegate proxy class responsible for managing navigation controller transitions by providing animation controllers.
///
/// This class acts as a bridge between the navigation controller and the transition handling process. It delegates
/// the responsibility of providing animations to the associated `NavigationControllerTransitionHandler`.
///
/// - Note: To use this class effectively, ensure that you initialize it with an appropriate
/// `NavigationControllerTransitionHandler` instance.
@MainActor
public class NavigationControllerDelegateProxy: NSObject, UINavigationControllerDelegate {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protocol NavigationControllerCreatable {
) -> NavigationController
}

/// A factory class for creating navigation controllers and their delegates.
public final class NavigationControllerFactory: NavigationControllerCreatable {

public init() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,37 @@ import SwiftUI
@MainActor
public class NavigationControllerTransitionHandler {

/// The provider responsible for supplying transitions.
public let provider: TransitionProvidable

public init(provider: TransitionProvidable) {
self.provider = provider
}

/// Asks the transition handler for an animator object to use when transitioning a view controller on or off the navigation stack.
///
/// - Parameters:
/// - navigationController: The navigation controller containing the view controllers involved in the transition.
/// - operation: The type of transition operation being performed.
/// - fromVC: The view controller that is being transitioned from.
/// - toVC: The view controller that is being transitioned to.
///
/// - Returns: An animator object conforming to `UIViewControllerAnimatedTransitioning`, or nil if no animation is desired.
func navigationController(
_ navigationController: UINavigationController,
animationControllerFor operation: UINavigationController.Operation,
from fromVC: UIViewController,
to toVC: UIViewController
) -> UIViewControllerAnimatedTransitioning? {
// Check if both fromVC and toVC conform to RouteProvider and retrieve their route information.
guard
let from = (fromVC as? RouteProvider)?.route,
let to = (toVC as? RouteProvider)?.route
else {
return nil
}

// Find the eligible transition from the provider based on the given route and operation.
if let transition = provider.transitions
.compactMap({ $0.transition })
.first(where: { $0.isEligible(from: from, to: to, operation: operation) }) {
Expand Down

0 comments on commit 16c8921

Please sign in to comment.