Closed olivaresf closed 3 months ago
I'm not seeing the current behavior you're experiencing. Applying the diff below, I see the "settings" page (actually /new
) presented correctly as a modal. Can you help me understand what I'm missing?
diff --git a/Demo/SceneController.swift b/Demo/SceneController.swift
index 0ad7ee4..1413775 100644
--- a/Demo/SceneController.swift
+++ b/Demo/SceneController.swift
@@ -93,11 +93,12 @@ extension SceneController: TurboNavigatorDelegate {
func visitableDidFailRequest(_ visitable: Visitable, error: Error, retryHandler: RetryBlock?) {
if let turboError = error as? TurboError, case let .http(statusCode) = turboError, statusCode == 401 {
promptForAuthentication()
- } else if let errorPresenter = visitable as? ErrorPresenter {
- errorPresenter.presentError(error, retryHandler: retryHandler)
} else {
let alert = UIAlertController(title: "Visit failed!", message: error.localizedDescription, preferredStyle: .alert)
- alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
+ alert.addAction(UIAlertAction(title: "Settings", style: .default) { [unowned self] _ in
+ navigator.route(rootURL.appendingPathComponent("new"))
+ })
+ alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
navigator.activeNavigationController.present(alert, animated: true)
}
}
I'm not seeing the current behavior you're experiencing. Applying the diff below, I see the "settings" page (actually /new) presented correctly as a modal. Can you help me understand what I'm missing?
In the diff you shared, Turbo will present a UIAlertController
which immediately dismisses itself when a button is tapped. That's definitely on me since I used that as an example, 🤦🏻♂️ sorry.
However, @svara confirmed my suspicion. Even though (in my mind) it makes more sense to check if the modal controller is presented than checking if the root controller is presenting, the real smell here is that if you're presenting outside of Turbo, it's your responsibility to make sure you dismiss too.
So, for now, I'm closing this one. Thanks both for your feedback!
I found another small issue. It's possible that users present a screen modally outside of TurboNavigator on TurboNavigator's main navigation controller.
For example:
turboNavigator.rootViewController
.route(url: settings)
is proposed.Expected: 5.
turboNavigator.modalRootViewController
is presented withSettings
as its root view controller. Current: 5.turboNavigator.rootViewController
is already presenting (the alert) soSettings
is pushed toturboNavigator.modalRootViewController
which exists but is not presented.The current behavior assumes
TurboNavigator
itself has presented the custom alert (2.) but no modal has actually been presented viaroute(url:)
. This causes future modals proposed throughroute(url:)
(4.) to never be presented. Instead, they're pushed/replaced onmodalRootViewController
since TurboNavigator believes it is already visible.Instead of checking whether the main nav controller has a presented modal, check if TurboNavigator's modal stack is being presented. This way, manually presenting a modal does not interfere with TurboNavigator's modal stack.