Routable

public protocol Routable: class

A Routable is a ViewController that takes active part to the execution of a navigation action. This is intended to be used in the few cases the RoutableWithConfiguration is not enough.

For instance, if we want a screen A to present B, the ViewController that is handling A, must conform to the Routable protocol.

Each Routable can be asked by the Navigator to perform a specific navigation task (like present another ViewController) based on the NavigationAction you dispatch (see Show or Hide).

   extension TodoListViewController: Routable {

     var routeIdentifier: RouteElementIdentifier: {
       return "todoList"
     }

     func show(indentifier: RouteElementIdentifier,
       from: RouteElementIdentifier,
       animated: Bool,
       context: Any?,
       completion: @escaping RoutingCompletion) -> Bool {

         let vc = NextViewController(store: self.store)
         self.present(vc, animated: animated, completion: completion)
         return true
     }
   }
   extension TodoListViewController: Routable {

     func hide(indentifier: RouteElementIdentifier,
       from: RouteElementIdentifier,
       animated: Bool,
       context: Any?,
       completion: @escaping RoutingCompletion) -> Bool {

         if identifier == self.routeIdentifier {
           self.dismiss(animated: animated, completion: completion)
           return true
         }
         return false
     }
   }
  • The identifier associated to this Routable.

       extension TodoListViewController: Routable {
    
         var routeIdentifier: RouteElementIdentifier: {
           return "todoList"
         }
       }
    

    Declaration

    Swift

    var routeIdentifier: RouteElementIdentifier
  • When a Show action is dispatched, the Navigator can ask this Routable to show another Routable identified by identifier calling this method. You must call the completion callback as soon as the navigation is completed. Return true if this Routable is handling the action, false otherwise.

       extension TodoListViewController: Routable {
    
         func show(indentifier: RouteElementIdentifier,
           from: RouteElementIdentifier,
           animated: Bool,
           context: Any?,
           completion: @escaping RoutingCompletion) -> Bool {
    
             let vc = NextViewController(store: self.store)
             self.present(vc, animated: animated, completion: completion)
             return true
         }
       }
    

    Default Implementation

    Declaration

    Swift

    func show(identifier: RouteElementIdentifier,
  • When a Hide action is dispatched, the Navigator can ask this Routable to hide itself or another Routable identified by identifier calling this method. Return true if this Routable is handling the action, false otherwise.

       extension TodoListViewController: Routable {
    
         func hide(indentifier: RouteElementIdentifier,
           from: RouteElementIdentifier,
           animated: Bool,
           context: Any?,
           completion: @escaping RoutingCompletion) -> Bool {
    
             if identifier == self.routeIdentifier {
               self.dismiss(animated: animated, completion: completion)
               return true
             }
             return false
         }
       }
    

    Default Implementation

    Declaration

    Swift

    func hide(identifier: RouteElementIdentifier,
  • When a Navigate action is dispatched, the Navigator can ask this Routable to hide/show itself or another Routable identified by identifier calling this method. Return true if this Routable is handling the action, false otherwise.

    Default Implementation

    Declaration

    Swift

    func change(from: RouteElementIdentifier,