damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit c4a9f2fdb27c4c337d7580a0a05d44082f025049
parent b1e0a6210987da97f0b3c66ce58ef85b6cb3c3d1
Author: Jericho Hasselbush <jericho@sal-et-lucem.com>
Date:   Wed, 13 Sep 2023 23:05:09 -0400

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 <jericho@sal-et-lucem.com>
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/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 @@ -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) + } + } } /*