ContainerCoordinator
open class ContainerCoordinator<T> : Coordinator<T>, HasChildren where T : UIViewController, T : Coordinated
The simplest Coordinator that can have other children Coordinators.
This does everything that Coordinator does plus managing the hierarchy and navigation flow, i.e. how the children are presented and where in the navigation flow.
The idea is that you can use it as a switch
between any kind of Coordinator.
-
An array containing the children Coordinators
Declaration
Swift
private(set) public var childCoordinators: [String : Coordinating] -
The currently presented UIViewController inside this Coordinator
Declaration
Swift
private(set) open var currentViewController: UIViewController?
-
Returns a cached children Coordinator if it exists
Use this method to verify if the Coordinator you want to present is not already in use to avoid wasting resources or creating conflicts
Declaration
Swift
public func getCached<C>(_ coordinatorType: C.Type) -> C?Parameters
coordinatorTypeThe Coordinator.Type from the Coordinator to be returned.
-
Analog to UIViewController’s
show(_ vc: UIViewController, sender: Any?)method but for Coordinators.It makes sure that the Coordinator is properly initialized before presenting its rootViewController.
Declaration
Swift
public func show(_ coordinator: Coordinating, sender: Any?)Parameters
coordinatorThe Coordinator with the rootViewController to be presented.
senderThe sender.
-
Analog to UIViewController’s
present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil)method but for Coordinators.It makes sure that the Coordinator is properly initialized before presenting its rootViewController
Declaration
Swift
public func present(_ coordinator: Coordinating, animated: Bool, completion: (() -> Void)?)Parameters
coordinatorThe Coordinator with the rootViewController to be presented.
animatedWhether the transition should be animated or not.
completionThe block to execute after the presentation finishes. This block has no return value and takes no parameters. You may specify nil for this parameter.
-
Analog to UIViewController’s
dismiss(animated flag: Bool, completion: (() -> Void)? = nil)method but for Coordinators.Declaration
Swift
public func dismiss(animated: Bool = true, completion: (() -> Void)? = nil)Parameters
animatedWhether the transition should be animated or not.
completionThe block to execute after the presentation finishes. This block has no return value and takes no parameters. You may specify nil for this parameter.
-
On a ContainerCoordinator, we can stack other Coordinators and change them with or without animation with this method.
You can override this method and use custom Animations/Transitions.
Declaration
Swift
open func root(_ coordinator: Coordinating, animated: Bool = false, completion: (() -> Void)? = nil)Parameters
coordinatorThe Coordinator with the rootViewController to be presented.
animatedWhether the transition should be animated or not.
completionThe block to execute after the presentation finishes. This block has no return value and takes no parameters. You may specify nil for this parameter.
View on GitHub
Install in Dash
ContainerCoordinator Class Reference