Guest User

Untitled

a guest
Sep 16th, 2019
109
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extension Coordinator {
  2. func allChildCoordinators() -> [Coordinator] {
  3. var childCoordinators = [Coordinator]()
  4. for childCoordinator in self.childCoordinators {
  5. childCoordinators.append(childCoordinator)
  6. childCoordinators += childCoordinator.allChildCoordinators()
  7. }
  8. return childCoordinators
  9. }
  10.  
  11. var lastChildCoordinator: Coordinator? {
  12. return allChildCoordinators().last
  13. }
  14. }
  15.  
  16.  
  17.  
  18. - if let transitionCoordinator = navigationController.topViewController?.transitionCoordinator {
  19. + guard let topViewController = navigationController.topViewController else { return }
  20. + if let transitionCoordinator = topViewController.transitionCoordinator {
  21. transitionCoordinator.notifyWhenInteractionChanges { (context) in
  22. guard !context.isCancelled && context.initiallyInteractive else { return }
  23. - _ = self.coordinator.childCoordinators.popLast()
  24. + guard let childIndex = navigationController.viewControllers.firstIndex(of: topViewController) else { return }
  25. + guard let coordinatorToClose = self.coordinator.allChildCoordinators()[safe: childIndex - 1] else { return }
  26. + coordinatorToClose.childCoordinators.removeAll()
  27. + print("coordinatorToClose: \(coordinatorToClose)")
  28. self.interactivePopGestureHandler.updateGestureState()
  29. }
  30. }
  31. }
RAW Paste Data