diff --git a/Mlem/Models/User-Interactable/Menu Function.swift b/Mlem/Models/User-Interactable/Menu Function.swift index 30502d7df..7aa1d10b1 100644 --- a/Mlem/Models/User-Interactable/Menu Function.swift +++ b/Mlem/Models/User-Interactable/Menu Function.swift @@ -6,19 +6,23 @@ // import Foundation +import SwiftUI enum MenuFunction: Identifiable { var id: String { switch self { case let .standard(standardMenuFunction): return standardMenuFunction.id - case let .share(shareMenuFunction): + case let .shareUrl(shareMenuFunction): return shareMenuFunction.id + case let .shareImage(shareImageFunction): + return shareImageFunction.id } } case standard(StandardMenuFunction) - case share(ShareMenuFunction) + case shareUrl(ShareMenuFunction) + case shareImage(ShareImageFunction) } // some convenience initializers because MenuFunction.standard(StandardMenuFunction...) is ugly @@ -40,7 +44,11 @@ extension MenuFunction { } static func shareMenuFunction(url: URL) -> MenuFunction { - MenuFunction.share(ShareMenuFunction(url: url)) + MenuFunction.shareUrl(ShareMenuFunction(url: url)) + } + + static func shareImageFunction(image: Image) -> MenuFunction { + MenuFunction.shareImage(ShareImageFunction(image: image)) } } @@ -51,6 +59,16 @@ struct ShareMenuFunction: Identifiable { let url: URL } +struct ShareImageFunction: Identifiable { + let id: String + let image: Image + + init(image: Image) { + self.image = image + self.id = UUID().uuidString + } +} + /// MenuFunction to perform a generic menu action struct StandardMenuFunction: Identifiable { var id: String { text } diff --git a/Mlem/Temp Image Viewer/ZoomableImageView.swift b/Mlem/Temp Image Viewer/ZoomableImageView.swift index 5c4e2af73..7deb3f2be 100644 --- a/Mlem/Temp Image Viewer/ZoomableImageView.swift +++ b/Mlem/Temp Image Viewer/ZoomableImageView.swift @@ -31,7 +31,7 @@ struct ZoomableImageView: View { .scaledToFit() .scaleEffect(zoom) .contextMenu { - ForEach(genMenuFunctions()) { item in + ForEach(genMenuFunctions(image: image)) { item in MenuButton(menuFunction: item, confirmDestructive: nil) } } @@ -73,7 +73,7 @@ struct ZoomableImageView: View { } } - func genMenuFunctions() -> [MenuFunction] { + func genMenuFunctions(image: Image) -> [MenuFunction] { var ret: [MenuFunction] = .init() ret.append(MenuFunction.standardMenuFunction( @@ -98,7 +98,7 @@ struct ZoomableImageView: View { } }) - ret.append(MenuFunction.share(ShareMenuFunction(url: url))) + ret.append(MenuFunction.shareImageFunction(image: image)) return ret } diff --git a/Mlem/Views/Shared/Components/Components/Menu Button.swift b/Mlem/Views/Shared/Components/Components/Menu Button.swift index 57cc4007d..f42d33134 100644 --- a/Mlem/Views/Shared/Components/Components/Menu Button.swift +++ b/Mlem/Views/Shared/Components/Components/Menu Button.swift @@ -14,8 +14,10 @@ struct MenuButton: View { var body: some View { switch menuFunction { - case let .share(shareMenuFunction): + case let .shareUrl(shareMenuFunction): ShareLink(item: shareMenuFunction.url) + case let .shareImage(shareImageFunction): + ShareLink(item: shareImageFunction.image, preview: .init("photo", image: shareImageFunction.image)) case let .standard(standardMenuFunction): let role: ButtonRole? = standardMenuFunction.destructiveActionPrompt != nil ? .destructive : nil Button(role: role) {