@@ -381,6 +381,8 @@ public final class LinkNavigator {
381381 let dependency : DependencyType
382382 let builders : [ RouteBuilder ]
383383
384+ private var coordinate : Coordinate = . init( sheetDidDismiss: { } )
385+
384386 public init (
385387 rootNavigationController: UINavigationController = . init( ) ,
386388 subNavigationController: UINavigationController = . init( ) ,
@@ -391,6 +393,11 @@ public final class LinkNavigator {
391393 self . subNavigationController = subNavigationController
392394 self . dependency = dependency
393395 self . builders = builders
396+
397+ self . coordinate = . init( sheetDidDismiss: { [ weak self] in
398+ self ? . subNavigationController. setViewControllers ( [ ] , animated: false )
399+ self ? . subNavigationController. presentationController? . delegate = . none
400+ } )
394401 }
395402}
396403
@@ -453,6 +460,7 @@ extension LinkNavigator: LinkNavigatorType {
453460 builders. first ( where: { $0. matchPath == path } ) ? . build ( self , items, dependency)
454461 }
455462 subNavigationController. setViewControllers ( new, animated: false )
463+ subNavigationController. presentationController? . delegate = coordinate
456464 rootNavigationController. present ( subNavigationController, animated: isAnimated)
457465 }
458466
@@ -469,6 +477,7 @@ extension LinkNavigator: LinkNavigatorType {
469477 }
470478
471479 subNavigationController. setViewControllers ( new, animated: false )
480+ subNavigationController. presentationController? . delegate = coordinate
472481 rootNavigationController. present ( subNavigationController, animated: isAnimated)
473482 }
474483
@@ -495,11 +504,16 @@ extension LinkNavigator: LinkNavigatorType {
495504 }
496505
497506 subNavigationController. setViewControllers ( new, animated: false )
507+ subNavigationController. presentationController? . delegate = coordinate
498508 rootNavigationController. present ( subNavigationController, animated: isAnimated)
499509 }
500510
501511 public func replace( paths: [ String ] , items: [ String : String ] , isAnimated: Bool ) {
502- subNavigationController. dismiss ( animated: isAnimated)
512+ rootNavigationController. dismiss ( animated: isAnimated, completion: {
513+ self . subNavigationController. setViewControllers ( [ ] , animated: isAnimated)
514+ self . subNavigationController. presentationController? . delegate = . none
515+ } )
516+
503517 let new = paths. compactMap { path in
504518 builders. first ( where: { $0. matchPath == path } ) ? . build ( self , items, dependency)
505519 }
@@ -533,7 +547,10 @@ extension LinkNavigator: LinkNavigatorType {
533547 }
534548
535549 guard isSubNavigationControllerPresented else { return }
536- currentActivityNavigationController. dismiss ( animated: isAnimated)
550+ currentActivityNavigationController. dismiss ( animated: isAnimated, completion: {
551+ self . subNavigationController. setViewControllers ( [ ] , animated: isAnimated)
552+ self . subNavigationController. presentationController? . delegate = . none
553+ } )
537554 }
538555
539556 public func remove( paths: [ String ] ) {
@@ -568,7 +585,11 @@ extension LinkNavigator: LinkNavigatorType {
568585
569586 public func close( isAnimated: Bool , completeAction: @escaping ( ) -> Void ) {
570587 guard isSubNavigationControllerPresented else { return }
571- rootNavigationController. dismiss ( animated: isAnimated, completion: completeAction)
588+ rootNavigationController. dismiss ( animated: isAnimated, completion: {
589+ completeAction ( )
590+ self . subNavigationController. setViewControllers ( [ ] , animated: isAnimated)
591+ self . subNavigationController. presentationController? . delegate = . none
592+ } )
572593 }
573594
574595 public func range( path: String ) -> [ String ] {
@@ -647,3 +668,17 @@ fileprivate extension LinkNavigator {
647668 . last ( where: { $0. matchPath == path } )
648669 }
649670}
671+
672+ extension LinkNavigator {
673+ fileprivate class Coordinate : NSObject , UIAdaptivePresentationControllerDelegate {
674+ init ( sheetDidDismiss: @escaping ( ) -> Void ) {
675+ self . sheetDidDismiss = sheetDidDismiss
676+ }
677+
678+ var sheetDidDismiss : ( ) -> Void
679+
680+ func presentationControllerDidDismiss( _ presentationController: UIPresentationController ) {
681+ sheetDidDismiss ( )
682+ }
683+ }
684+ }
0 commit comments