hotwired / turbo-ios

iOS framework for making Turbo native apps
MIT License
891 stars 87 forks source link

How to access webview with TurboNavigator? #222

Open bibstha opened 3 months ago

bibstha commented 3 months ago

This may be due to stale documentation. Looks like the TurboNavigator branch is the most active branch. The QuickStart says the

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?
    private let navigator = TurboNavigator()

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let _ = (scene as? UIWindowScene) else { return }
        window?.rootViewController = navigator.rootViewController
        navigator.route(baseURL)

With this, the Session object and the webView object are encapsulated inside TurboNavigator. If I want to set configs to webView, eg: webView.allowsLinkPreview = false, how do I do that?

iamjohnford commented 3 months ago

I'm not sure if this is the best way, but if you're using the demo code, you can insert webView.allowsLinkPreview = false into the section that creates the custom webView:

https://github.com/hotwired/turbo-ios/blob/3ce4f977e1dc8eb5b2eeefb81a07bc344e230584/Demo/SceneController.swift#L18-L29

Another option specifically for link previews is CSS. If you're targeting turbo native in your HTML tag, you can do something like this:

html[data-turbo-native] {
  -webkit-touch-callout: none;
}