-
Notifications
You must be signed in to change notification settings - Fork 59
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
Handle URL Click in the editor #15
Comments
Do you recognize the issue that i have mentioned in the above comment? Could you please reply to it. |
Apologies; I put the eyes emoji to let you know I've read it. I'm in the middle of finals and will report back on May 1st. |
Thank you for your reply. I'm looking forward to it. |
HI @tomcruise-007 I just remembered why I don't allow it. This view is technically an "editor" so if you had an accidental click on the URL, then you would've been taken somewhere else. |
i think it's really bad if user can not click into link, can u help about this problem. Sometimes we use this as "View", not editor |
As a "view", gotcha. IIRC, I thought if you disabled the editor and only showed the editor, users would be able to click the link. However, it would not appear in SFSafariViewController; instead, it'd show up in the WKWebView and you wouldn't be able to get back to the editor view. So in the following, I'll show how to present SFSafariViewController. It's been awhile since I've looked at this package, but here are my two guesses for what to do: Disclaimer: it's been nearly a year since I've properly written in Swift, so adjust accordingly if I get concepts wrong. Guess 1: Use this: RichEditorView/Sources/RichEditorView/RichEditorView.swift Lines 30 to 32 in ed734f6
Basically, your VC needs to inherit the delegate. Use the delegate to define that function. Finally, the contents of the code @objc optional func richEditor(_ editor: RichEditorView, shouldInteractWith url: URL) -> Bool {
let safariVC = SFSafariViewController(url);
present(safariVC);
return true;
} Guess 2: Assuming we only need to use SFSafariViewController, first import it. Then create a new class inheriting the editor view. Take a look at this func's bottom portion of the code: RichEditorView/Sources/RichEditorView/RichEditorView.swift Lines 483 to 491 in ed734f6
So we override this func. We now need to decide if the given url is a link: override public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if !navigationAction.request.url?.absoluteString.hasPrefix(callbackPrefix) && navigationAction.navigationType == .linkActivated {
if let url = navigationAction.request.url {
let safariVC = SFSafariViewController(url);
present(safariVC);
return decisionHandler(WKNavigationActionPolicy.cancel);
}
}
return super().webView(webView, navigationAction, decisionHandler);
} Again, please adjust accordingly. If you don't mind, too, please post your code so that others know what to do as well. |
yeah, i just use your solution 1, thanks so much <3 |
Hi,
I was able to insert link in the editor. But couldn't implement autolink action on it, making the link clickable. It seems that there was no callback triggered while we click on the URL from js file. Any workarounds for this?. I hope you will found a suitable solution for this issue.
The text was updated successfully, but these errors were encountered: