From c4a9f2fdb27c4c337d7580a0a05d44082f025049 Mon Sep 17 00:00:00 2001 From: Jericho Hasselbush Date: Wed, 13 Sep 2023 23:05:09 -0400 Subject: [PATCH] ui: hold tap to preview status URL Applied a WKWebkitView inside a .contextMenu to show preview status for URL links in user status messages. Closes: https://github.com/damus-io/damus/issues/1523 Changelog-Added: Hold tap to preview status URL Signed-off-by: Jericho Hasselbush Signed-off-by: William Casarin --- damus/Components/Status/UserStatusView.swift | 24 +++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/damus/Components/Status/UserStatusView.swift b/damus/Components/Status/UserStatusView.swift index a1444d47..8bea043a 100644 --- a/damus/Components/Status/UserStatusView.swift +++ b/damus/Components/Status/UserStatusView.swift @@ -7,7 +7,7 @@ import SwiftUI import MediaPlayer - +import WebKit struct UserStatusView: View { @ObservedObject var status: UserStatusModel @@ -35,6 +35,15 @@ struct UserStatusView: View { openURL(url) } } + .contextMenu( + menuItems: { + if let url = st.url { + Button(url.absoluteString, action: { openURL(url) }) } + }, preview: { + if let url = st.url { + URLPreview(url: url) + } + }) } var body: some View { @@ -49,6 +58,19 @@ struct UserStatusView: View { } } + + struct URLPreview: UIViewRepresentable { + var url: URL + + func makeUIView(context: Context) -> WKWebView { + return WKWebView() + } + + func updateUIView(_ wkView: WKWebView, context: Context) { + let request = URLRequest(url: url) + wkView.load(request) + } + } } /*