Add context menu and draggability to attachment image views (#2142)

* Factor out MediaUIShareLink

* Add share link to attachment image view

* Make attachment image views draggable

* Add copy actions to attachment image view
This commit is contained in:
fwcd 2024-07-29 07:56:22 +02:00 committed by GitHub
parent 4f9cb2e86a
commit 9af98c3921
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 7 deletions

View file

@ -22,6 +22,23 @@ struct MediaUIAttachmentImageView: View {
.progressViewStyle(.circular) .progressViewStyle(.circular)
} }
} }
.draggable(MediaUIImageTransferable(url: url))
.contextMenu {
MediaUIShareLink(url: url, type: .image)
Button {
Task {
let transferable = MediaUIImageTransferable(url: url)
UIPasteboard.general.image = UIImage(data: await transferable.fetchData())
}
} label: {
Label("status.media.contextmenu.copy", systemImage: "doc.on.doc")
}
Button {
UIPasteboard.general.url = url
} label: {
Label("status.action.copy-link", systemImage: "link")
}
}
} }
} }
} }

View file

@ -0,0 +1,16 @@
import SwiftUI
struct MediaUIShareLink: View, @unchecked Sendable {
let url: URL
let type: DisplayType
var body: some View {
if type == .image {
let transferable = MediaUIImageTransferable(url: url)
ShareLink(item: transferable, preview: .init("status.media.contextmenu.share",
image: transferable))
} else {
ShareLink(item: url)
}
}
}

View file

@ -6,13 +6,7 @@ struct ShareToolbarItem: ToolbarContent, @unchecked Sendable {
var body: some ToolbarContent { var body: some ToolbarContent {
ToolbarItem(placement: .topBarTrailing) { ToolbarItem(placement: .topBarTrailing) {
if type == .image { MediaUIShareLink(url: url, type: type)
let transferable = MediaUIImageTransferable(url: url)
ShareLink(item: transferable, preview: .init("status.media.contextmenu.share",
image: transferable))
} else {
ShareLink(item: url)
}
} }
} }
} }