BaseCoordinator

open class BaseCoordinator<RouteType, TransitionType> : Coordinator where RouteType : Route, TransitionType : TransitionProtocol

BaseCoordinator can (and is encouraged to) be used as a superclass for any custom implementation of a coordinator.

It is also encouraged to use already provided subclasses of BaseCoordinator such as NavigationCoordinator, TabBarCoordinator, ViewCoordinator, SplitCoordinator and PageCoordinator.

  • The child coordinators that are currently in the view hierarchy. When performing a transition, children are automatically added and removed from this array depending on whether they are in the view hierarchy.

    Declaration

    Swift

    public private(set) var children: [Presentable]
  • This initializer trigger a route before the coordinator is made visible.

    Declaration

    Swift

    public init(rootViewController: RootViewController, initialRoute: RouteType?)

    Parameters

    initialRoute

    If a route is specified, it is triggered before making the coordinator visible.

  • This initializer performs a transition before the coordinator is made visible.

    Declaration

    Swift

    public init(rootViewController: RootViewController, initialTransition: TransitionType?)

    Parameters

    initialTransition

    If a transition is specified, it is performed before making the coordinator visible.

  • Declaration

    Swift

    open func presented(from presentable: Presentable?)
  • Declaration

    Swift

    public func removeChildrenIfNeeded()
  • Declaration

    Swift

    public func addChild(_ presentable: Presentable)
  • Declaration

    Swift

    public func removeChild(_ presentable: Presentable)
  • This method prepares transitions for routes. Override this method to define transitions for triggered routes.

    Declaration

    Swift

    open func prepareTransition(for route: RouteType) -> TransitionType

    Parameters

    route

    The triggered route for which a transition is to be prepared.

    Return Value

    The prepared transition.

  • Declaration

    Swift

    public func registerParent(_ presentable: Presentable & AnyObject)
  • Shortcut for BaseCoordinator.TransitionType.RootViewController

    Declaration

    Swift

    public typealias RootViewController = TransitionType.RootViewController
  • Register an interactive transition triggered by a gesture recognizer.

    Also consider registerInteractiveTransition(for:triggeredBy:progress:shouldFinish:completion:) as it might make it easier to implement an interactive transition. This is meant for cases where the other method does not provide enough customization options.

    A target is added to the gestureRecognizer so that the handler is executed every time the state of the gesture recognizer changes.

    Note

    Use unregisterInteractiveTransition(triggeredBy:) to remove previously added interactive transitions.

    Declaration

    Swift

    open func registerInteractiveTransition<GestureRecognizer: UIGestureRecognizer>(
        for route: RouteType,
        triggeredBy recognizer: GestureRecognizer,
        handler: @escaping (_ handlerRecognizer: GestureRecognizer, _ transition: () -> TransitionAnimation?) -> Void,
        completion: PresentationHandler? = nil)

    Parameters

    route

    The route to be triggered when the gestureRecognizer begins. Make sure that the transition behind is interactive as otherwise the transition is simply performed.

    recognizer

    The gesture recognizer to be used to update the interactive transition.

    handler

    The handler to update the interaction controller of the animation generated by the given transition closure.

    handlerRecognizer

    The gestureRecognizer with which the handler has been registered.

    transition

    The closure to perform the transition. It returns the transition animation to control the interaction controller of. TransitionAnimation.start() is automatically called.

    completion

    The closure to be called whenever the transition completes. Hint: Might be called multiple times but only once per performing the transition.

  • Register an interactive transition triggered by a gesture recognizer.

    To get more customization options, check out registerInteractiveTransition(for:triggeredBy:handler:completion:).

    A target is added to the gestureRecognizer so that the handler is executed every time the state of the gesture recognizer changes.

    Note

    Use unregisterInteractiveTransition(triggeredBy:) to remove previously added interactive transitions.

    Declaration

    Swift

    open func registerInteractiveTransition<GestureRecognizer: UIGestureRecognizer>(
        for route: RouteType,
        triggeredBy recognizer: GestureRecognizer,
        progress: @escaping (GestureRecognizer) -> CGFloat,
        shouldFinish: @escaping (GestureRecognizer) -> Bool,
        completion: PresentationHandler? = nil)

    Parameters

    route

    The route to be triggered when the gestureRecognizer begins. Make sure that the transition behind is interactive as otherwise the transition is simply performed.

    recognizer

    The gesture recognizer to be used to update the interactive transition.

    progress

    Return the progress as CGFloat between 0 (start) and 1 (finish).

    shouldFinish

    Decide depending on the gestureRecognizer’s state whether to finish or cancel a given transition.

    completion

    The closure to be called whenever the transition completes. Hint: Might be called multiple times but only once per performing the transition.

  • Unregisters a previously registered interactive transition.

    Unregistering is not mandatory to prevent reference cycles, etc. It is useful, though, to remove previously registered interactive transitions that are no longer needed or wanted.

    Declaration

    Swift

    open func unregisterInteractiveTransitions(triggeredBy recognizer: UIGestureRecognizer)

    Parameters

    recognizer

    The recognizer to unregister interactive transitions for. This method will unregister all interactive transitions with that gesture recognizer.