Bubble/Threaded/Components/ShareSheetController.swift

45 lines
1.5 KiB
Swift
Raw Normal View History

2024-01-21 16:34:26 +01:00
//Made by Lumaa
import Foundation
import SwiftUI
import UIKit
2024-01-25 01:54:51 +01:00
import LinkPresentation
2024-01-21 16:34:26 +01:00
/// Share sheet
struct ShareSheet: UIViewControllerRepresentable {
let image: UIImage
2024-01-25 01:54:51 +01:00
let status: Status
2024-01-21 16:34:26 +01:00
2024-01-25 01:54:51 +01:00
class ActivityPreview: NSObject, UIActivityItemSource {
let image: UIImage
let status: Status
init(image: UIImage, status: Status) {
self.image = image
self.status = status
}
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
image
}
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
nil
}
func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
let metadata = LPLinkMetadata()
metadata.imageProvider = NSItemProvider(object: image)
metadata.title = status.reblogAsAsStatus?.content.asRawText ?? status.content.asRawText + String("\n\n\(status.url ?? AppInfo.website)")
return metadata
}
2024-01-21 16:34:26 +01:00
}
2024-01-25 01:54:51 +01:00
func makeUIViewController(context: Context) -> UIActivityViewController {
UIActivityViewController(activityItems: [image, ActivityPreview(image: image, status: status)], applicationActivities: nil)
2024-01-21 16:34:26 +01:00
}
2024-01-25 01:54:51 +01:00
func updateUIViewController(_ uiViewController: UIActivityViewController, context: Context) {}
2024-01-21 16:34:26 +01:00
}