Skip to content

Commit

Permalink
Merge branch 'develop' into feature/735_HeroViewPropertyViewContext_C…
Browse files Browse the repository at this point in the history
…rash
  • Loading branch information
JoeMatt authored May 6, 2022
2 parents e00bc08 + 9f8fe2b commit a260a48
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions Sources/Extensions/UIViewController+Hero.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public extension HeroExtension where Base: UIViewController {
}

/**
Replace the current view controller with another VC on the navigation/modal stack.
Replace the current view controller with another VC on the navigation/modal/root view of UIWindow stack.
*/
func replaceViewController(with next: UIViewController, completion: (() -> Void)? = nil) {
let hero = next.transitioningDelegate as? HeroTransition ?? Hero.shared
Expand All @@ -324,21 +324,19 @@ public extension HeroExtension where Base: UIViewController {
hero.forceNotInteractive = true
}
navigationController.setViewControllers(viewControllers: vcs, animated: true, completion: completion)
} else if let container = base.view.superview {
let parentVC = base.presentingViewController
} else if let container = base.view.superview, let parentVC = base.presentingViewController {
hero.transition(from: base, to: next, in: container) { [weak base] finished in
guard let base = base else { return }
guard finished else { return }

guard let base = base, finished else { return }
next.view.window?.addSubview(next.view)
if let parentVC = parentVC {
base.dismiss(animated: false) {
parentVC.present(next, animated: false, completion: completion)
}
} else {
parentVC?.view.window?.rootViewController = next
base.dismiss(animated: false) {
parentVC.present(next, animated: false, completion: completion)
}
}
} else if let baseWindow = base.view.window, baseWindow.rootViewController == base {
hero.transition(from: base, to: next, in: baseWindow) { [weak base] finished in
guard let base = base, finished else { return }
baseWindow.rootViewController = next
}
}
}
}
Expand Down

0 comments on commit a260a48

Please sign in to comment.