Routable
public protocol Routable : AnyObject
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 { get } -
show(identifier:Default implementationfrom: animated: context: completion: ) When a
Showaction is dispatched, theNavigatorcan ask this Routable to show another Routable identified byidentifiercalling this method. You must call the completion callback as soon as the navigation is completed. Returntrueif this Routable is handling the action,falseotherwise.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
Show a route element
Declaration
Swift
func show( identifier: RouteElementIdentifier, from: RouteElementIdentifier, animated: Bool, context: Any?, completion: @escaping RoutingCompletion ) -> Bool -
hide(identifier:Default implementationfrom: animated: context: completion: ) When a
Hideaction is dispatched, theNavigatorcan ask this Routable to hide itself or another Routable identified byidentifiercalling this method. Returntrueif this Routable is handling the action,falseotherwise.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
Hide a route element
Declaration
Swift
func hide( identifier: RouteElementIdentifier, from: RouteElementIdentifier, animated: Bool, context: Any?, completion: @escaping RoutingCompletion ) -> Bool -
change(from:Default implementationto: animated: context: completion: ) When a
Navigateaction is dispatched, theNavigatorcan ask this Routable to hide/show itself or another Routable identified byidentifiercalling this method. Returntrueif this Routable is handling the action,falseotherwise.Default Implementation
Change a route element
Declaration
Swift
func change( from: RouteElementIdentifier, to: RouteElementIdentifier, animated: Bool, context: Any?, completion: @escaping RoutingCompletion )
View on GitHub
Routable Protocol Reference