Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Expose current navigation controller #61

Closed
wants to merge 1 commit into from

Conversation

joemasilotti
Copy link
Owner

Helpful when completely custom navigation is required, like presenting a modal from WKUIDelegate.webView(_:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:completionHandler:), for example:

import WebKit

extension SceneDelegate: WKUIDelegate {
    func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
        let alert = UIAlertController(title: message, message: nil, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .destructive) { _ in
            completionHandler()
        })
        self.turboNavigator.currentNavigationController.present(alert, animated: true)
    }
}

That last line is important - if we don't have access to the currently visible navigation controller the app can crash. For example, if we try to present this alert on the main/root controller while a modal is displayed.

I like this approach because it gives the developer full control over when/how they want to present the dialog. But it also requires them to implement both this and the confirm() function.

Part of me thinks that both of these should be included directly in Turbo Navigator. But then if someone wants to do something entirely custom with WKUIDelegate I'm not sure how to expose that.

Helpful when completely custom navigation is required, like presenting a
modal from:

```
WKUIDelegate.webView(_:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:completionHandler:)
```
@joemasilotti
Copy link
Owner Author

Closed in favor of #74.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant