Bubble/Threaded/Data/ShareableImage.swift

25 lines
647 B
Swift
Raw Normal View History

2023-12-29 11:17:37 +01:00
//Made by Lumaa
import Foundation
import SwiftUI
2023-12-30 20:57:41 +01:00
// Doesn't seem to work?
2023-12-29 11:17:37 +01:00
struct AsyncImageTransferable: Codable, Transferable {
let url: URL
func fetchAsImage() async -> Image {
let data = try? await URLSession.shared.data(from: url).0
guard let data, let uiimage = UIImage(data: data) else {
return Image(systemName: "photo")
}
return Image(uiImage: uiimage)
}
2023-12-30 20:57:41 +01:00
// MARK: A synchronous exporter should be used
2023-12-29 11:17:37 +01:00
static var transferRepresentation: some TransferRepresentation {
ProxyRepresentation { media in
await media.fetchAsImage()
}
}
}