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

Remove configuration in favor of delegate #75

Closed
wants to merge 5 commits into from

Conversation

joemasilotti
Copy link
Owner

This PR builds on #73, so the diff showing is bigger than it "actually" is.

The changes move the configuration of the user agent and web view instantiation to the TurboNavigationDelegate protocol. This makes customizing the web view a bit cleaner when integrating with Strada. And I found that a lot of folks were confused by the block used previously, so hopefully this makes more sense!

Before

This also must be run before the TurboNavigator instance is created, otherwise the block will have already executed and the custom web view configuration will not apply.

TurboConfig.shared.makeCustomWebView = { configuration in
    configuration.applicationNameForUserAgent? +=
        " \(Strada.userAgentSubstring(for: BridgeComponent.all))"

    let webView = WKWebView(frame: .zero, configuration: configuration)
    Bridge.initialize(webView)
    return webView
}

After

extension SceneDelegate: TurboNavigationDelegate {
    func webView(configuration: WKWebViewConfiguration) -> WKWebView {
        configuration.applicationNameForUserAgent? +=
            " \(Strada.userAgentSubstring(for: BridgeComponent.all))"

        let webView = WKWebView(frame: .zero, configuration: configuration)
        Bridge.initialize(webView)
        return webView
    }
}

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