Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set additional wkWebView settings #1097

Closed
timboozle opened this issue Jan 4, 2019 · 16 comments
Closed

How to set additional wkWebView settings #1097

timboozle opened this issue Jan 4, 2019 · 16 comments

Comments

@timboozle
Copy link

I am using Capacitor without Ionic and I want to set additional WKWebView settings like:

  • allowsBackForwardNavigationGestures
  • allowsLinkPreview
  • scrollView.bounces

How would this be possible?

@jcesarmobile
Copy link
Member

It's not possible at the moment

@timboozle
Copy link
Author

Thanks, so it's not possible at all to set those variables? Or is there a workaround maybe? Sorry, no experience with Swift but would like to have those things in my app

@jcesarmobile
Copy link
Member

the only "workaround" is to manually edit the code to set the values you want

@chris-carrington
Copy link

Thank you ionic team for all your contributions to the community, allowing the ability to "allowsBackForwardNavigationGestures" would be much appreciated

@mlynch
Copy link
Contributor

mlynch commented May 19, 2019

Thanks, certainly something we could explore adding down the road

@realityfilter
Copy link

On our project we had the need to register a custom url scheme handler. This can only
be done before the webview is initialized. I think one could easily refactor CAPBridgeViewController
to have factory methods for setting up the webview and the webview configuration and make the
class and the factory methods open. Within a subclass CAPBridgeViewController one would be able to override as needed and specify the controller in the main storyboard.

If this is a viable solution I could make a PR for this. In the meantime we swizzle WKWebViewConfiguration.

@macdja38
Copy link
Contributor

macdja38 commented Oct 3, 2019

What does everyone think of adding a static method that plugins can implement to allow them to modify the WKWebViewConfiguration?

Something like this

    public static override func configureWKWebView(_ configuration: WKWebViewConfiguration) {
        CAPLog.print("Wouldn't it be cool if this got called?")
        configuration.ignoresViewportScaleLimits = true
    }

My only issue would plugins might step on each others toes, but I'm not sure how to possibly get around that.

@jcesarmobile
Copy link
Member

since the issue is about the webview settings, those can be changed at any time, and as plugins have a reference to the webview, they can change any of the settings, so I'll just close.

@realityfilter @macdja38 as the WKWebViewConfiguration is a different issue, maybe you should create a new issue about it, or we can just keep @macdja38 PR as reference. Or you can send a separate PR since you mentioned a different idea.

@jcesarmobile
Copy link
Member

In capacitor 3 you can use your own WebView, so you can configure it the way you want

for changing values during runtime, better create a plugin of your own that exposes the properties you need

@mb21
Copy link

mb21 commented Jul 5, 2021

So the recommended way in capacitor 3 is to use a custom ViewController and then implementing the capacitorDidLoad function? And there do something like:

 webview.allowsBackForwardNavigationGestures = true

@jcesarmobile
Copy link
Member

It depends on what you want to change, if they are values that can be changed at runtime I recommend creating a plugin that allows to change those values.

@mb21
Copy link

mb21 commented Jul 6, 2021

Thanks for the reply! We just want to have allowsBackForwardNavigationGestures set to true... and don't want to change it afterwards. What's the reason you recommend doing that as a plugin instead of in capacitorDidLoad? is the plugin-api more stable? I'm a little bit worried of race conditions and such... but maybe there's no reason to?

@wr9
Copy link

wr9 commented Mar 24, 2022

@mb21 what did you end up doing?

@mb21
Copy link

mb21 commented Mar 24, 2022

we ended up using a custom ViewController that looks like this:

import UIKit
import Capacitor

class MyViewController: CAPBridgeViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        webView!.allowsBackForwardNavigationGestures = true
    }
}

@wr9
Copy link

wr9 commented Mar 24, 2022

@mb21 thank you, much appreciated!

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 10, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants