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

feat(ios): Add ios capacitor config to use a custom wkwebview #3095

Closed
wants to merge 1 commit into from

Conversation

rtrap95
Copy link

@rtrap95 rtrap95 commented Jun 11, 2020

I needed I way to hide the context menu when text is selected on ios which it seems to be impossible in iOS13 (css doesn't work). I created this pull request to give users the possibility to create a custom wkwebview and use it. This way I can write a class like this (always extend WKWebView):

class CustomWKWebView: WKWebView{
    override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        return false
    }
}

and use it to hide the context menu.
User could add this in capacitor.config.json to enable this feature otherwise normal WKWebView is used:

{
  "ios":{
    "customWebView":"NameOfTheCustomWebView"
  }
}

Let me know what do you think about this solution

@rtrap95 rtrap95 changed the title Add ios capacitor config to use a custom wkwebview feat(ios): Add ios capacitor config to use a custom wkwebview Jun 12, 2020
@ikeith
Copy link
Contributor

ikeith commented Jul 1, 2020

@rtrap95 thanks for the PR! However, we don't feel that adding custom class names to the config file is the route we want to go down. Our aim is to support this use case in 3.0 by allowing you to subclass CAPBridgeViewController in your app to accomplish this type of override.

I created #3191 to track that issue.

@ikeith ikeith closed this Jul 1, 2020
@rtrap95
Copy link
Author

rtrap95 commented Jul 1, 2020

Thank you @ikeith ! I'm looking forward to this feature! Let me know if I can help in some way.

@joewoodhouse
Copy link

@ikeith Not sure I totally follow how sublassing CAPBridgeViewController and extending WKWebView are the same thing? I have a similar requirement where I need to override a function of WKWebView (point()) but I've got not obvious way to hook into that. Even if I hack/subsclass CAPBridgeViewController that doesn't let me do this, does it?

@ikeith
Copy link
Contributor

ikeith commented Nov 11, 2020

They aren't the same thing, but making CAPBridgeViewController explicitly subclassable provides ways to address a lot of different use-cases. In 2.x, the instantiation and configuration of the webview and bridge communication all happens in one big block so overriding it isn't useful; it was never designed for that. But when it's refactored we can provide individual methods that subclasses could override to change how it works. To address this particular example, it could have a method like UIView's layerClass to supply the class to use instead of hardcoding WKWebView. And it could have methods to modify properties on the WKWebViewConfiguration or the web view after it's been created.

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

Successfully merging this pull request may close these issues.

3 participants