Add context menu previews
This commit is contained in:
parent
444c4c053d
commit
a0a12f3865
@ -75,6 +75,7 @@ class BrowserWebViewController: UIViewController {
|
|||||||
webView.backgroundColor = .systemBackground
|
webView.backgroundColor = .systemBackground
|
||||||
webView.isOpaque = false
|
webView.isOpaque = false
|
||||||
webView.navigationDelegate = self
|
webView.navigationDelegate = self
|
||||||
|
webView.uiDelegate = self
|
||||||
// it is safe to set the delegate of the web view's internal scroll view becuase WebKit takes care of forwarding between its internal delegate and our own
|
// it is safe to set the delegate of the web view's internal scroll view becuase WebKit takes care of forwarding between its internal delegate and our own
|
||||||
webView.scrollView.delegate = scrollViewDelegate
|
webView.scrollView.delegate = scrollViewDelegate
|
||||||
// this doesn't default to .default :S
|
// this doesn't default to .default :S
|
||||||
@ -247,3 +248,26 @@ extension BrowserWebViewController: WKNavigationDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension BrowserWebViewController: WKUIDelegate {
|
||||||
|
func webView(_ webView: WKWebView, contextMenuConfigurationForElement elementInfo: WKContextMenuElementInfo, completionHandler: @escaping (UIContextMenuConfiguration?) -> Void) {
|
||||||
|
guard let url = elementInfo.linkURL,
|
||||||
|
url.scheme == "gemini" else {
|
||||||
|
completionHandler(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let config = UIContextMenuConfiguration(identifier: nil) {
|
||||||
|
return BrowserWebViewController(navigator: self.navigator, url: url)
|
||||||
|
} actionProvider: { (_) in
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
completionHandler(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
func webView(_ webView: WKWebView, contextMenuForElement elementInfo: WKContextMenuElementInfo, willCommitWithAnimator animator: UIContextMenuInteractionCommitAnimating) {
|
||||||
|
animator.preferredCommitStyle = .pop
|
||||||
|
animator.addCompletion {
|
||||||
|
self.navigator.changeURL(elementInfo.linkURL!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user