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?) -> VoidParameters
rootViewControllerThe rootViewController to perform the transition on.
optionsThe options on how to perform the transition, e.g. whether it should be animated or not.
completionThe 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
Animationobject. If the transition does not use any transition animations,nilis 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
presentablesThe presentables this transition is putting into the view hierarchy, if specifiable. These presentables are used in the deep-linking feature.
animationInUseThe 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
registerInteractiveTransitionmethod in your coordinator.performThe 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’sperformTransitionmethod 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) -> TransitionParameters
presentableThe presentable to be pushed onto the navigation stack.
animationThe 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
nilhere to leave animations as they were set for the presentable before. You can useAnimation.defaultto 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) -> TransitionParameters
animationThe animation to set for the presentable. Only its dismissalAnimation is used for the pop-transition. Specify
nilhere to leave animations as they were set for the presentable before. You can useAnimation.defaultto 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) -> TransitionParameters
presentableThe presentable to pop to. Make sure this presentable is in the rootViewController’s navigation stack before performing such a transition.
animationThe animation to set for the presentable. Only its dismissalAnimation is used for the pop-transition. Specify
nilhere to leave animations as they were set for the presentable before. You can useAnimation.defaultto 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) -> TransitionParameters
animationThe animation to set for the presentable. Only its dismissalAnimation is used for the pop-transition. Specify
nilhere to leave animations as they were set for the presentable before. You can useAnimation.defaultto 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) -> TransitionParameters
presentablesThe presentables to make up the navigation stack after the transition is done.
animationThe 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
nilhere to leave animations as they were set for the presentables before. You can useAnimation.defaultto reset the previously set animations on all presentables.
-
Sets the current page(s) of the rootViewController. Make sure to set
UIPageViewController.isDoubleSidedto the appropriate setting before executing this transition.Declaration
Swift
public static func set(_ first: Presentable, _ second: Presentable? = nil, direction: UIPageViewController.NavigationDirection) -> TransitionParameters
firstThe first page being shown. If second is specified as
nil, this reflects a single page being shown.secondThe second page being shown. This page is optional, as your rootViewController can be used with
isDoubleSidedenabled or not.directionThe 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) -> TransitionParameters
presentablesThe tabs to be set are defined by the presentables’ viewControllers.
animationThe animation to be used. If you specify
nilhere, 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) -> TransitionParameters
presentableThe tab to be selected is the presentable’s viewController. Make sure that this is one of the previously specified tabs of the rootViewController.
animationThe animation to be used. If you specify
nilhere, 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) -> TransitionParameters
indexThe index of the tab to be selected. Make sure that there is a tab at the specified index.
animationThe animation to be used. If you specify
nilhere, the default animation by UIKit is used.
-
Shows a viewController by calling
showon the rootViewController.Note
Prefer
Transition.pushwhen using transitions on aUINavigationControllerrootViewController. In contrast to this transition, you can specify an animation.Declaration
Swift
public static func show(_ presentable: Presentable) -> TransitionParameters
presentableThe presentable to be shown as a primary view controller.
-
Shows a detail viewController by calling
showDetailon the rootViewController.Note
Prefer
Transition.pushwhen using transitions on aUINavigationControllerrootViewController. In contrast to this transition, you can specify an animation.Declaration
Swift
public static func showDetail(_ presentable: Presentable) -> TransitionParameters
presentableThe 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) -> TransitionParameters
presentableThe presentable to be presented.
animationThe animation to be set as the presentable’s transitioningDelegate. Specify
nilto not override the current transitioningDelegate andAnimation.defaultto 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) -> TransitionParameters
presentableThe presentable to be presented.
animationThe animation to be set as the presentable’s transitioningDelegate. Specify
nilto not override the current transitioningDelegate andAnimation.defaultto 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) -> TransitionParameters
presentableThe presentable to be embedded.
containerThe container to embed the presentable in.
-
Transition to call dismiss on the rootViewController. Also take a look at the
dismisstransition, which calls dismiss on the rootViewController’s presentedViewController, if present.Declaration
Swift
public static func dismissToRoot(animation: Animation? = nil) -> TransitionParameters
animationThe animation to be used by the rootViewController’s presentedViewController. Specify
nilto not override its transitioningDelegate orAnimation.defaultto 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) -> TransitionParameters
animationThe animation to be used by the rootViewController’s presentedViewController. Specify
nilto not override its transitioningDelegate orAnimation.defaultto 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
transitionsThe 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 : CoordinatorParameters
routeThe route to be triggered on the coordinator.
coordinatorThe 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
routetransition instead.Declaration
Swift
public static func trigger<R>(_ route: R.RouteType, on router: R) -> Transition where R : RouterParameters
routeThe route to be triggered on the coordinator.
routerThe 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) -> TransitionParameters
transitionThe transition to be performed.
viewControllerThe viewController to perform the transition on.
View on GitHub
Transition Structure Reference