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

iOS WKWebView NavigationDelegate methods with handlers doesn't work #3843

Closed
slartus opened this issue Oct 21, 2023 · 3 comments
Closed

iOS WKWebView NavigationDelegate methods with handlers doesn't work #3843

slartus opened this issue Oct 21, 2023 · 3 comments
Labels
ios question Not a bug, but question or comment

Comments

@slartus
Copy link

slartus commented Oct 21, 2023

Describe the bug
Overridden methods in NavigationDelegate with handlers do not work.
If you override the method, for example, of checking the availability of navigation and allow navigation to any URLs, then there will be a blank page.
When you remove this method, the links open.

example code:

@OptIn(ExperimentalForeignApi::class)
@Composable
actual fun WebView(modifier: Modifier, url: String) {
    UIKitView(
        modifier = modifier,
        factory = {
            WKWebView(
                frame = CGRectZero.readValue(),
            ).apply {
                navigationDelegate = WKNavigationDelegate()
                loadRequest(
                    request = NSURLRequest(
                        uRL = NSURL(string = url),
                    )
                )
            }
        }
    )
}

class WKNavigationDelegate : NSObject(), WKNavigationDelegateProtocol {
    override fun webView(
        webView: WKWebView,
        decidePolicyForNavigationAction: WKNavigationAction,
        decisionHandler: (WKNavigationActionPolicy) -> Unit,
    ) {
        decisionHandler(WKNavigationActionPolicy.WKNavigationActionPolicyAllow)
    }
}

same behavior with certificate verification method:

override fun webView(
        webView: WKWebView,
        didReceiveAuthenticationChallenge: NSURLAuthenticationChallenge,
        completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Unit
    )

Affected platforms

  • iOS

Versions

  • Kotlin version*: 1.9.10
  • Compose Multiplatform version*: 1.5.2, 1.5.3
  • OS version(s)* (required for Desktop and iOS issues): 16.4

To Reproduce
Download compose-multiplatform-template project and replace shared folder with shared.zip

@slartus slartus added bug Something isn't working submitted labels Oct 21, 2023
@KevinnZou
Copy link

I also encountered this issue in my WebView project and could not find a solution.

@dima-avdeev-jb
Copy link
Contributor

Hello! Thanks for Issue, you may try to use remember function to save a hard link to navigationDelegate:

val rememberedNavigationDelegate = remember { WKNavigationDelegate() }

See examples here: https://github.com/dima-avdeev-jb/issue-3843-ios-webview

I will close this Issue, but if you will have some related questions, of something goes wrong - please feel free to reopen it

@dima-avdeev-jb dima-avdeev-jb added question Not a bug, but question or comment and removed submitted bug Something isn't working labels Oct 23, 2023
@okushnikov
Copy link

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ios question Not a bug, but question or comment
Projects
None yet
Development

No branches or pull requests

4 participants