Add context menu for image fix #113

This commit is contained in:
Thomas Ricouard 2023-01-19 07:56:24 +01:00
parent e81ea4ee81
commit 987a655227
2 changed files with 43 additions and 1 deletions

View file

@ -68,7 +68,7 @@ public struct StatusCardView: View {
}
Divider()
Button {
UIPasteboard.general.string = card.url.absoluteString
UIPasteboard.general.url = card.url
} label: {
Label("Copy link", systemImage: "doc.on.doc")
}

View file

@ -4,8 +4,11 @@ import Models
import NukeUI
import Shimmer
import SwiftUI
import Nuke
public struct StatusMediaPreviewView: View {
@Environment(\.openURL) private var openURL
@EnvironmentObject private var preferences: UserPreferences
@EnvironmentObject private var quickLook: QuickLook
@EnvironmentObject private var theme: Theme
@ -69,6 +72,9 @@ public struct StatusMediaPreviewView: View {
await quickLook.prepareFor(urls: attachments.compactMap { $0.url }, selectedURL: attachment.url!)
}
}
.contextMenu {
contextMenuForMedia(mediaAttachement: attachment)
}
} else {
if isNotifications || theme.statusDisplayStyle == .compact {
HStack {
@ -251,6 +257,9 @@ public struct StatusMediaPreviewView: View {
await quickLook.prepareFor(urls: attachments.compactMap { $0.url }, selectedURL: attachment.url!)
}
}
.contextMenu {
contextMenuForMedia(mediaAttachement: attachment)
}
}
}
@ -301,4 +310,37 @@ public struct StatusMediaPreviewView: View {
.position(x: 30, y: 30)
.buttonStyle(.borderedProminent)
}
@ViewBuilder
private func contextMenuForMedia(mediaAttachement: MediaAttachment) -> some View {
if let url = mediaAttachement.url {
ShareLink(item: url) {
Label("Share this image", systemImage: "square.and.arrow.up")
}
Button { openURL(url) } label: {
Label("View in Browser", systemImage: "safari")
}
Divider()
Button {
Task {
do {
let image = try await ImagePipeline.shared.image(for: url).image
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
} catch { }
}
} label: {
Label("Save image", systemImage: "square.and.arrow.down")
}
Button {
Task {
do {
let image = try await ImagePipeline.shared.image(for: url).image
UIPasteboard.general.image = image
} catch { }
}
} label: {
Label("Copy image", systemImage: "doc.on.doc")
}
}
}
}