diff options
| author | Bug Magnet <marco.nikic@mullvad.net> | 2023-09-13 16:28:16 +0200 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2023-09-13 16:28:16 +0200 |
| commit | 571d6bd61dfb7151ca28ebd4cce0516f710b7c9f (patch) | |
| tree | d01938a194efeac8bebf10616b31dbd23bb47f04 /ios/Routing/Router/ApplicationRouter.swift | |
| parent | c0ee7f5b8686a4ed67cec01b574a43c7e9ef0287 (diff) | |
| parent | f47bbebe41337e471a602f969a05dd06e8904779 (diff) | |
| download | mullvadvpn-571d6bd61dfb7151ca28ebd4cce0516f710b7c9f.tar.xz mullvadvpn-571d6bd61dfb7151ca28ebd4cce0516f710b7c9f.zip | |
Merge branch 'coordinate-alert-presentation-ios-175'
Diffstat (limited to 'ios/Routing/Router/ApplicationRouter.swift')
| -rw-r--r-- | ios/Routing/Router/ApplicationRouter.swift | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/ios/Routing/Router/ApplicationRouter.swift b/ios/Routing/Router/ApplicationRouter.swift index 2de0cbc3ff..d565875143 100644 --- a/ios/Routing/Router/ApplicationRouter.swift +++ b/ios/Routing/Router/ApplicationRouter.swift @@ -53,10 +53,11 @@ public final class ApplicationRouter<RouteType: AppRouteProtocol> { /** Enqueue route for presetnation. */ - public func present(_ route: RouteType, animated: Bool = true) { + public func present(_ route: RouteType, animated: Bool = true, metadata: Any? = nil) { enqueue(PendingRoute( operation: .present(route), - animated: animated + animated: animated, + metadata: metadata )) } @@ -81,7 +82,7 @@ public final class ApplicationRouter<RouteType: AppRouteProtocol> { } private func enqueue(_ pendingRoute: PendingRoute<RouteType>) { - logger.debug("Enqueue \(pendingRoute.operation).") + logger.debug("\(pendingRoute.operation).") pendingRoutes.append(pendingRoute) @@ -93,6 +94,7 @@ public final class ApplicationRouter<RouteType: AppRouteProtocol> { private func presentRoute( _ route: RouteType, animated: Bool, + metadata: Any?, completion: @escaping (PendingPresentationResult) -> Void ) { /** @@ -117,7 +119,7 @@ public final class ApplicationRouter<RouteType: AppRouteProtocol> { } /** - Drop duplicate routes. + Drop duplicate exclusive routes. */ if route.isExclusive, modalStack.contains(route.routeGroup) { completion(.drop) @@ -135,8 +137,15 @@ public final class ApplicationRouter<RouteType: AppRouteProtocol> { /** Check if route can be presented above the last route in the modal stack. */ - if let lastRouteGroup = modalStack.last, route.routeGroup.isModal, - (lastRouteGroup > route.routeGroup) || (route.isExclusive && lastRouteGroup == route.routeGroup) { + if let + // Get current modal route. + lastRouteGroup = modalStack.last, + // Check if incoming route is modal. + route.routeGroup.isModal, + // Check whether incoming route can be presented on top of current. + (lastRouteGroup > route.routeGroup) || + // OR, check whether incoming exclusive route can be presented on top of current. + (lastRouteGroup >= route.routeGroup && route.isExclusive) { completion(.blockedByModalContext) return } @@ -145,7 +154,9 @@ public final class ApplicationRouter<RouteType: AppRouteProtocol> { Consult with delegate whether the route should still be presented. */ if delegate.applicationRouter(self, shouldPresent: route) { - delegate.applicationRouter(self, route: route, animated: animated) { coordinator in + let context = RoutePresentationContext(route: route, isAnimated: animated, metadata: metadata) + + delegate.applicationRouter(self, presentWithContext: context, animated: animated) { coordinator in /* Synchronize router when modal controllers are removed by swipe. */ @@ -276,7 +287,7 @@ public final class ApplicationRouter<RouteType: AppRouteProtocol> { switch pendingRoute.operation { case let .present(route): - presentRoute(route, animated: pendingRoute.animated) { result in + presentRoute(route, animated: pendingRoute.animated, metadata: pendingRoute.metadata) { result in switch result { case .success, .drop: self.finishPendingRoute(pendingRoute) |
