TabBarCoordinator

open class TabBarCoordinator<T> : ContainerCoordinator<T>, UITabBarControllerDelegate where T : UITabBarController, T : Coordinated

The TabBarCoordinator is a specialized ContainerCoordinator for UITabBarController

It is to be used with a UITabBarCoordinator as rootViewController and has specific logic to cope with the intricacies of said UITabBarController. It has specialized presentation methods that mirror the ones from UITabBarController.

  • Starts the Coordinator.

    In this particular case, it also assigns the rootViewController as the UITabBarControllerDelegate. If you override this method do not forget to call super.start() or the subclass won’t work properly.

    Declaration

    Swift

    open override func start(with completion: @escaping () -> Void)

    Parameters

    completion

    An optional Callback executed at the end.

  • Analog to UITabBarController’s setControllers().

    Use this to set the UITabBarController children Coordinators and its UIViewControllers/Tabs pairs. This is usually called inside start() because the UITabBarController needs to know its children in order to populate the TabBar with the corresponding buttons.

    Declaration

    Swift

    public func setCoordinators(_ coordinators: [Coordinating])
  • Callback for when a Tab is tapped.

    Override this method to intercept Tab taps so that you can do things before and after the Tab is changed, like setting loading states, async calls, etc.

    By default it selects the Coordinator immediately.

    Declaration

    Swift

    open func tabTapped(for coordinator: Coordinating)

    Parameters

    coordinator

    Coordinator corresponding to the tapped Tab.

  • Allows you to programatically select a Tab corresponding to the Coordinator you want

    Declaration

    Swift

    public func select(_ coordinator: Coordinating)

    Parameters

    coordinator

    Coordinator to be selected.

  • Deactivate automatic Tab switch on UITabBarController It calls tabTapped with the Coordinator from the specific UIViewController

    Declaration

    Swift

    public func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool