Transition
public struct Transition<RootViewController> : TransitionProtocol where RootViewController : UIViewController
This struct represents the common implementation of the TransitionProtocol
.
It is used in every of the provided BaseCoordinator
subclasses and provides all transitions implemented in XCoordinator.
Transitions
are defined by a Transition.Perform
closure.
It further provides different context information such as Transition.presentable
and Transition.animation
.
You can create your own custom transitions using Transition.init(presentable:animation:perform:)
or
use one of the many provided static functions to create the most common transitions.
Note
Transitions have a generic constraint to the rootViewController in use. Therefore, not all transitions are available in every coordinator. Make sure to specify theRootViewController
type of the TransitionType
of your coordinator as precise as possible
to get all already available transitions.
-
Perform is the type of closure used to perform the transition.
Declaration
Swift
public typealias PerformClosure = (_ rootViewController: RootViewController, _ options: TransitionOptions, _ completion: PresentationHandler?) -> Void
Parameters
rootViewController
The rootViewController to perform the transition on.
options
The options on how to perform the transition, e.g. whether it should be animated or not.
completion
The completion handler of the transition. It is called when the transition (including all animations) is completed.
-
The presentables this transition is putting into the view hierarchy. This is especially useful for deep-linking.
Declaration
Swift
public var presentables: [Presentable] { get }
-
The transition animation this transition is using, i.e. the presentation or dismissal animation of the specified
Animation
object. If the transition does not use any transition animations,nil
is returned.Declaration
Swift
public var animation: TransitionAnimation? { get }
-
Create your custom transitions with this initializer.
Extending Transition with static functions to create transitions with this initializer (instead of calling this initializer in your
prepareTransition(for:)
method) is advised as it makes reuse easier.Declaration
Swift
public init(presentables: [Presentable], animationInUse: TransitionAnimation?, perform: @escaping PerformClosure)
Parameters
presentables
The presentables this transition is putting into the view hierarchy, if specifiable. These presentables are used in the deep-linking feature.
animationInUse
The transition animation this transition is using during the transition, i.e. the present animation of a presenting transition or the dismissal animation of a dismissing transition. Make sure to specify an animation here to use your transition with the
registerInteractiveTransition
method in your coordinator.perform
The perform closure executes the transition. To create custom transitions, make sure to call the completion handler after all animations are done. If applicable, make sure to use the TransitionOptions to, e.g., decide whether a transition should be animated or not.
-
Performs a transition on the given viewController.
Warning
Do not call this method directly. Instead use your coordinator’sperformTransition
method or trigger a specified route (latter option is encouraged).Declaration
Swift
public func perform(on rootViewController: RootViewController, with options: TransitionOptions, completion: PresentationHandler?)
-
Pushes a presentable on the rootViewController’s navigation stack.
Declaration
Swift
public static func push(_ presentable: Presentable, animation: Animation? = nil) -> Transition
Parameters
presentable
The presentable to be pushed onto the navigation stack.
animation
The animation to set for the presentable. Its presentationAnimation will be used for the immediate push-transition, its dismissalAnimation is used for the pop-transition, if not otherwise specified. Specify
nil
here to leave animations as they were set for the presentable before. You can useAnimation.default
to reset the previously set animations on this presentable. -
Pops the topViewController from the rootViewController’s navigation stack.
Declaration
Swift
public static func pop(animation: Animation? = nil) -> Transition
Parameters
animation
The animation to set for the presentable. Only its dismissalAnimation is used for the pop-transition. Specify
nil
here to leave animations as they were set for the presentable before. You can useAnimation.default
to reset the previously set animations on this presentable. -
Pops viewControllers from the rootViewController’s navigation stack until the specified presentable is reached.
Declaration
Swift
public static func pop(to presentable: Presentable, animation: Animation? = nil) -> Transition
Parameters
presentable
The presentable to pop to. Make sure this presentable is in the rootViewController’s navigation stack before performing such a transition.
animation
The animation to set for the presentable. Only its dismissalAnimation is used for the pop-transition. Specify
nil
here to leave animations as they were set for the presentable before. You can useAnimation.default
to reset the previously set animations on this presentable. -
Pops viewControllers from the rootViewController’s navigation stack until only one viewController is left.
Declaration
Swift
public static func popToRoot(animation: Animation? = nil) -> Transition
Parameters
animation
The animation to set for the presentable. Only its dismissalAnimation is used for the pop-transition. Specify
nil
here to leave animations as they were set for the presentable before. You can useAnimation.default
to reset the previously set animations on this presentable. -
Replaces the navigation stack of the rootViewController with the specified presentables.
Declaration
Swift
public static func set(_ presentables: [Presentable], animation: Animation? = nil) -> Transition
Parameters
presentables
The presentables to make up the navigation stack after the transition is done.
animation
The animation to set for the presentable. Its presentationAnimation will be used for the transition animation of the top-most viewController, its dismissalAnimation is used for any pop-transition of the whole navigation stack, if not otherwise specified. Specify
nil
here to leave animations as they were set for the presentables before. You can useAnimation.default
to reset the previously set animations on all presentables.
-
Sets the current page(s) of the rootViewController. Make sure to set
UIPageViewController.isDoubleSided
to the appropriate setting before executing this transition.Declaration
Swift
public static func set(_ first: Presentable, _ second: Presentable? = nil, direction: UIPageViewController.NavigationDirection) -> Transition
Parameters
first
The first page being shown. If second is specified as
nil
, this reflects a single page being shown.second
The second page being shown. This page is optional, as your rootViewController can be used with
isDoubleSided
enabled or not.direction
The direction in which the transition should be animated.
-
Transition to set the tabs of the rootViewController with an optional custom animation.
Note
Only the presentation animation of the Animation object is used.
Declaration
Swift
public static func set(_ presentables: [Presentable], animation: Animation? = nil) -> Transition
Parameters
presentables
The tabs to be set are defined by the presentables’ viewControllers.
animation
The animation to be used. If you specify
nil
here, the default animation by UIKit is used. -
Transition to select a tab with an optional custom animation.
Note
Only the presentation animation of the Animation object is used.
Declaration
Swift
public static func select(_ presentable: Presentable, animation: Animation? = nil) -> Transition
Parameters
presentable
The tab to be selected is the presentable’s viewController. Make sure that this is one of the previously specified tabs of the rootViewController.
animation
The animation to be used. If you specify
nil
here, the default animation by UIKit is used. -
Transition to select a tab with an optional custom animation.
Note
Only the presentation animation of the Animation object is used.
Declaration
Swift
public static func select(index: Int, animation: Animation? = nil) -> Transition
Parameters
index
The index of the tab to be selected. Make sure that there is a tab at the specified index.
animation
The animation to be used. If you specify
nil
here, the default animation by UIKit is used.
-
Shows a viewController by calling
show
on the rootViewController.Note
Prefer
Transition.push
when using transitions on aUINavigationController
rootViewController. In contrast to this transition, you can specify an animation.Declaration
Swift
public static func show(_ presentable: Presentable) -> Transition
Parameters
presentable
The presentable to be shown as a primary view controller.
-
Shows a detail viewController by calling
showDetail
on the rootViewController.Note
Prefer
Transition.push
when using transitions on aUINavigationController
rootViewController. In contrast to this transition, you can specify an animation.Declaration
Swift
public static func showDetail(_ presentable: Presentable) -> Transition
Parameters
presentable
The presentable to be shown as a detail view controller.
-
Transition to present the given presentable on the rootViewController.
The present-transition might also be helpful as it always presents on top of what is currently presented.
Declaration
Swift
public static func presentOnRoot(_ presentable: Presentable, animation: Animation? = nil) -> Transition
Parameters
presentable
The presentable to be presented.
animation
The animation to be set as the presentable’s transitioningDelegate. Specify
nil
to not override the current transitioningDelegate andAnimation.default
to reset the transitioningDelegate to use the default UIKit animations. -
Transition to present the given presentable. It uses the rootViewController’s presentedViewController, if present, otherwise it is equivalent to
presentOnRoot
.Declaration
Swift
public static func present(_ presentable: Presentable, animation: Animation? = nil) -> Transition
Parameters
presentable
The presentable to be presented.
animation
The animation to be set as the presentable’s transitioningDelegate. Specify
nil
to not override the current transitioningDelegate andAnimation.default
to reset the transitioningDelegate to use the default UIKit animations. -
Transition to embed the given presentable in a specific container (i.e. a view or viewController).
Declaration
Swift
public static func embed(_ presentable: Presentable, in container: Container) -> Transition
Parameters
presentable
The presentable to be embedded.
container
The container to embed the presentable in.
-
Transition to call dismiss on the rootViewController. Also take a look at the
dismiss
transition, which calls dismiss on the rootViewController’s presentedViewController, if present.Declaration
Swift
public static func dismissToRoot(animation: Animation? = nil) -> Transition
Parameters
animation
The animation to be used by the rootViewController’s presentedViewController. Specify
nil
to not override its transitioningDelegate orAnimation.default
to fall back to the default UIKit animations. -
Transition to call dismiss on the rootViewController’s presentedViewController, if present. Otherwise, it is equivalent to
dismissToRoot
.Declaration
Swift
public static func dismiss(animation: Animation? = nil) -> Transition
Parameters
animation
The animation to be used by the rootViewController’s presentedViewController. Specify
nil
to not override its transitioningDelegate orAnimation.default
to fall back to the default UIKit animations. -
No transition at all. May be useful for testing or debugging purposes, or to ignore specific routes.
Declaration
Swift
public static func none() -> Transition
-
With this transition you can chain multiple transitions of the same type together.
Declaration
Swift
public static func multiple<C>(_ transitions: C) -> Transition where C : Collection, C.Element == Transition<RootViewController>
Parameters
transitions
The transitions to be chained to form the new transition.
-
Use this transition to trigger a route on another coordinator. TransitionOptions and PresentationHandler used during the execution of this transitions are forwarded.
Declaration
Swift
public static func route<C>(_ route: C.RouteType, on coordinator: C) -> Transition where C : Coordinator
Parameters
route
The route to be triggered on the coordinator.
coordinator
The coordinator to trigger the route on.
-
Use this transition to trigger a route on another router. TransitionOptions and PresentationHandler used during the execution of this transitions are forwarded.
Peeking is not supported with this transition. If needed, use the
route
transition instead.Declaration
Swift
public static func trigger<R>(_ route: R.RouteType, on router: R) -> Transition where R : Router
Parameters
route
The route to be triggered on the coordinator.
router
The router to trigger the route on.
-
Performs a transition on a different viewController than the coordinator’s rootViewController.
This might be helpful when creating a coordinator for a specific viewController would create unnecessary complicated code.
Declaration
Swift
public static func perform<TransitionType: TransitionProtocol>(_ transition: TransitionType, on viewController: TransitionType.RootViewController) -> Transition
Parameters
transition
The transition to be performed.
viewController
The viewController to perform the transition on.