From 33c2646ea192a7141a7eb4e64aa5e160015f426f Mon Sep 17 00:00:00 2001 From: fwcd <30873659+fwcd@users.noreply.github.com> Date: Mon, 29 Jul 2024 07:56:42 +0200 Subject: [PATCH] Make status rows draggable (#2141) --- .../StatusKit/Sources/StatusKit/Row/StatusRowView.swift | 1 + .../Sources/StatusKit/Row/StatusRowViewModel.swift | 6 +++++- .../StatusKit/Row/Subviews/StatusRowCardView.swift | 1 + .../StatusKit/Row/Subviews/StatusRowContextMenu.swift | 8 +++----- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Packages/StatusKit/Sources/StatusKit/Row/StatusRowView.swift b/Packages/StatusKit/Sources/StatusKit/Row/StatusRowView.swift index 7b0c2c7b..3add988d 100644 --- a/Packages/StatusKit/Sources/StatusKit/Row/StatusRowView.swift +++ b/Packages/StatusKit/Sources/StatusKit/Row/StatusRowView.swift @@ -124,6 +124,7 @@ public struct StatusRowView: View { } } } + .if(viewModel.url != nil) { $0.draggable(viewModel.url!) } .contextMenu { contextMenu .onAppear { diff --git a/Packages/StatusKit/Sources/StatusKit/Row/StatusRowViewModel.swift b/Packages/StatusKit/Sources/StatusKit/Row/StatusRowViewModel.swift index 1e149dd2..eceb66cc 100644 --- a/Packages/StatusKit/Sources/StatusKit/Row/StatusRowViewModel.swift +++ b/Packages/StatusKit/Sources/StatusKit/Row/StatusRowViewModel.swift @@ -105,7 +105,11 @@ import SwiftUI status.reblog?.inReplyToId != nil || status.reblog?.inReplyToAccountId != nil || status.inReplyToId != nil || status.inReplyToAccountId != nil } - + + var url: URL? { + (status.reblog?.url ?? status.url).flatMap(URL.init(string:)) + } + @ViewBuilder func makeBackgroundColor(isHomeTimeline: Bool) -> some View { if isHomeTimeline, theme.showContentGradient { diff --git a/Packages/StatusKit/Sources/StatusKit/Row/Subviews/StatusRowCardView.swift b/Packages/StatusKit/Sources/StatusKit/Row/Subviews/StatusRowCardView.swift index 332c89b8..0c69c0c8 100644 --- a/Packages/StatusKit/Sources/StatusKit/Row/Subviews/StatusRowCardView.swift +++ b/Packages/StatusKit/Sources/StatusKit/Row/Subviews/StatusRowCardView.swift @@ -81,6 +81,7 @@ public struct StatusRowCardView: View { .stroke(.gray.opacity(0.35), lineWidth: 1) } } + .draggable(url) .contextMenu { ShareLink(item: url) { Label("status.card.share", systemImage: "square.and.arrow.up") diff --git a/Packages/StatusKit/Sources/StatusKit/Row/Subviews/StatusRowContextMenu.swift b/Packages/StatusKit/Sources/StatusKit/Row/Subviews/StatusRowContextMenu.swift index e44ae4b9..ad5cb675 100644 --- a/Packages/StatusKit/Sources/StatusKit/Row/Subviews/StatusRowContextMenu.swift +++ b/Packages/StatusKit/Sources/StatusKit/Row/Subviews/StatusRowContextMenu.swift @@ -88,9 +88,7 @@ struct StatusRowContextMenu: View { Divider() Menu("status.action.share-title") { - if let urlString = viewModel.status.reblog?.url ?? viewModel.status.url, - let url = URL(string: urlString) - { + if let url = viewModel.url { ShareLink(item: url, subject: Text(viewModel.status.reblog?.account.safeDisplayName ?? viewModel.status.account.safeDisplayName), message: Text(viewModel.status.reblog?.content.asRawText ?? viewModel.status.content.asRawText)) @@ -133,7 +131,7 @@ struct StatusRowContextMenu: View { } } - if let url = URL(string: viewModel.status.reblog?.url ?? viewModel.status.url ?? "") { + if let url = viewModel.url { Button { UIApplication.shared.open(url) } label: { Label("status.action.view-in-browser", systemImage: "safari") } @@ -152,7 +150,7 @@ struct StatusRowContextMenu: View { } Button { - UIPasteboard.general.string = viewModel.status.reblog?.url ?? viewModel.status.url + UIPasteboard.general.url = viewModel.url } label: { Label("status.action.copy-link", systemImage: "link") }