Skip to content

Commit

Permalink
Merge pull request #33 from allaboutapps/fix/navigation-coordinator-d…
Browse files Browse the repository at this point in the history
…elgate-handover

refactor delegate handover
  • Loading branch information
mpoimer authored Sep 1, 2022
2 parents 7c649cf + 2386aa7 commit 76852f7
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions Sources/Toolbox/Coordinators/NavigationCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ open class NavigationCoordinator: Coordinator {
print("remove: \(pushedViewControllers.count) from \(self)")
if let parentCoordinator = parentCoordinator as? NavigationCoordinator, pushedViewControllers.isEmpty {
parentCoordinator.removeChild(self)
navigationController.delegate = parentCoordinator
if isPresented {
navigationController.presentationController?.delegate = parentCoordinator
}
handOverDelegates(to: parentCoordinator) // give delegate back to parent
}
}
}
Expand Down Expand Up @@ -78,11 +75,9 @@ open class NavigationCoordinator: Coordinator {
public func push(_ coordinator: NavigationCoordinator, animated: Bool) {
assert(coordinator.navigationController == navigationController, "Navigation Coordinator should only be pushed on the same UINavigationController! Hand over existing UINavigationController in init!")
addChild(coordinator)
navigationController.delegate = coordinator // hand delegate to last coordinator

coordinator.isPresented = isPresented
if isPresented {
navigationController.presentationController?.delegate = coordinator
}
handOverDelegates(to: coordinator) // hand delegate to next coordinator
}

public func popCoordinator(animated: Bool) {
Expand All @@ -92,7 +87,15 @@ open class NavigationCoordinator: Coordinator {
if let childCoordinator = childCoordinator {
removeChild(childCoordinator)
}
navigationController.delegate = self

handOverDelegates(to: self) // I am the delegate now
}

func handOverDelegates(to navigationCoordinator: NavigationCoordinator) {
navigationController.delegate = navigationCoordinator
if isPresented {
navigationController.presentationController?.delegate = navigationCoordinator
}
}

// MARK: Reset
Expand Down

0 comments on commit 76852f7

Please sign in to comment.