ContainerAdapter

@MainActor
public protocol ContainerAdapter

Provides universal properties and methods of the ContainerViewController instance.

ContainerViewControllers are different from the simple ones in that they can contain child view controllers which are also containers or simple ones. These view controllers are available out of the box: UINavigationController, UITabBarController and so on, but there can be custom ones created as well.

All the container view controller have the following properties:

  1. The list of all the view controllers that they contain.
  2. One or more view controllers are currently visible.
  3. They can make one of these view controllers visible.
  4. They can replace all of their contained view controllers.

Properties to implement

  • overriddenParentViewController Default implementation

    Provides an ability to override default parent. nil means use default parent of the UIViewController.

    Default Implementation

    Defaults to nil.

    Declaration

    Swift

    @MainActor
    var overriddenParentViewController: UIViewController? { get }
  • All UIViewController instances that adapting ContainerViewController currently has in the stack

    Declaration

    Swift

    @MainActor
    var containedViewControllers: [UIViewController] { get }
  • The UIViewController instances out of the containedViewControllers that are currently visible on the screen The visibleViewControllers are the subset of the containedViewControllers.

    Declaration

    Swift

    @MainActor
    var visibleViewControllers: [UIViewController] { get }

Methods to implement

  • Each container view controller adapter should implement this method for the Router to know how to make its particular child view controller visible.

    NB: completion block must be called.

    Declaration

    Swift

    @MainActor
    func makeVisible(_ viewController: UIViewController, animated: Bool, completion: @escaping (RoutingResult) -> Void)

    Parameters

    viewController

    The UIViewController to make active (visible).

    animated

    If ContainerViewController is able to do so - make container active animated or not.

  • Each container view controller adapter should implement this method for the Router to know how to replace all the view controllers in this particular container view controller.

    NB: completion block must be called.

    Declaration

    Swift

    @MainActor
    func setContainedViewControllers(_ containedViewControllers: [UIViewController], animated: Bool, completion: @escaping (RoutingResult) -> Void)

    Parameters

    containedViewControllers

    A UIViewController instances to replace.

    animated

    If ContainerViewController is able to do so - replace contained view controllers animated or not.

Helper methods

  • contains(_:) Extension method

    Checks if the provided view controller is present amongst the contained view controllers.

    Declaration

    Swift

    @MainActor
    func contains(_ viewController: UIViewController) -> Bool

    Parameters

    viewController

    UIViewController instance

    Return Value

    true if present, false otherwise.

  • isVisible(_:) Extension method

    Checks if the provided view controller is present amongst the visible view controllers.

    Declaration

    Swift

    @MainActor
    func isVisible(_ viewController: UIViewController) -> Bool

    Parameters

    viewController

    UIViewController instance

    Return Value

    true if present, false otherwise.