@@ -11,26 +11,21 @@ final class RoutesCoordinator {
1111 case activeNavigation( UUID )
1212 }
1313
14- typealias MainRouteSetupHandler = ( RouteInterface ? , _ legIndex: UInt32 , _ completion: @escaping ( Result < RouteInfo , Error > ) -> Void ) -> Void
15- typealias AlternativeRoutesSetupHandler = ( [ RouteInterface ] , _ completion: @escaping ( Result < [ RouteAlternative ] , Error > ) -> Void ) -> Void
14+ typealias RoutesSetupHandler = ( _ mainRoute: RouteInterface ? , _ legIndex: UInt32 , _ alternativeRoutes: [ RouteInterface ] , _ completion: @escaping ( Result < RouteInfo ? , Error > ) -> Void ) -> Void
1615
1716 private struct ActiveNavigationSession {
1817 let uuid : UUID
1918 }
2019
21- private let mainRouteSetupHandler : MainRouteSetupHandler
22- let alternativeRoutesSetupHandler : AlternativeRoutesSetupHandler
20+ private let routesSetupHandler : RoutesSetupHandler
2321 /// The lock that protects mutable state in `RoutesCoordinator`.
2422 private let lock : NSLock
2523 private var state : State
2624
2725 /// Create a new coordinator that will coordinate requests to set main and alternative routes.
28- /// - Parameter mainRouteSetupHandler: The handler that passes `RouteInterface` object to underlying Navigator as main route.
29- /// - Parameter alternativeRoutesSetupHandler: The handler that passes `RouteInterface` array to underlying Navigator as alternative routes.
30- init ( mainRouteSetupHandler: @escaping MainRouteSetupHandler ,
31- alternativeRoutesSetupHandler: @escaping AlternativeRoutesSetupHandler ) {
32- self . mainRouteSetupHandler = mainRouteSetupHandler
33- self . alternativeRoutesSetupHandler = alternativeRoutesSetupHandler
26+ /// - Parameter routesSetupHandler: The handler that passes main and alternative route's`RouteInterface` objects to underlying Navigator.
27+ init ( routesSetupHandler: @escaping RoutesSetupHandler ) {
28+ self . routesSetupHandler = routesSetupHandler
3429 lock = . init( )
3530 state = . passiveNavigation
3631 }
@@ -42,7 +37,8 @@ final class RoutesCoordinator {
4237 func beginActiveNavigation( with route: RouteInterface ,
4338 uuid: UUID ,
4439 legIndex: UInt32 ,
45- completion: @escaping ( Result < RouteInfo , Error > ) -> Void ) {
40+ alternativeRoutes: [ RouteInterface ] ,
41+ completion: @escaping ( Result < RouteInfo ? , Error > ) -> Void ) {
4642 lock. lock ( )
4743 if case . activeNavigation( let currentUUID) = state, currentUUID != uuid {
4844 os_log ( " [BUG] Two simultaneous active navigation sessions. This might happen if there are two NavigationViewController or RouteController instances exists at the same time. Profile the app and make sure that NavigationViewController is deallocated once not in use. " , log: log, type: . fault)
@@ -51,12 +47,12 @@ final class RoutesCoordinator {
5147 state = . activeNavigation( uuid)
5248 lock. unlock ( )
5349
54- mainRouteSetupHandler ( route, legIndex, completion)
50+ routesSetupHandler ( route, legIndex, alternativeRoutes , completion)
5551 }
5652
5753 /// - Parameters:
5854 /// - uuid: The UUID that was passed to `RoutesCoordinator.beginActiveNavigation(with:uuid:completion:)` method.
59- func endActiveNavigation( with uuid: UUID , completion: @escaping ( Result < RouteInfo , Error > ) -> Void ) {
55+ func endActiveNavigation( with uuid: UUID , completion: @escaping ( Result < RouteInfo ? , Error > ) -> Void ) {
6056 lock. lock ( )
6157 guard case . activeNavigation( let currentUUID) = state, currentUUID == uuid else {
6258 lock. unlock ( )
@@ -66,7 +62,7 @@ final class RoutesCoordinator {
6662 state = . passiveNavigation
6763 lock. unlock ( )
6864 // TODO: Is it safe to set the leg index to 0 when unsetting a route?
69- mainRouteSetupHandler ( nil , 0 , completion)
65+ routesSetupHandler ( nil , 0 , [ ] , completion)
7066 }
7167}
7268
0 commit comments