Bubble/Threaded/Data/ShareableOnlineImage.swift

25 lines
616 B
Swift
Raw Normal View History

2023-12-29 11:17:37 +01:00
//Made by Lumaa
import Foundation
import SwiftUI
2024-01-06 15:27:55 +01:00
// Dimillian fixed it - https://mastodon.social/@dimillian/111708477095374920
struct ShareableOnlineImage: Codable, Transferable {
2023-12-29 11:17:37 +01:00
let url: URL
2024-01-06 15:27:55 +01:00
func fetchAsImage() -> Image {
let data = try? Data(contentsOf: url)
2023-12-29 11:17:37 +01:00
guard let data, let uiimage = UIImage(data: data) else {
return Image(systemName: "photo")
}
return Image(uiImage: uiimage)
}
static var transferRepresentation: some TransferRepresentation {
ProxyRepresentation { media in
2024-01-06 15:27:55 +01:00
media.fetchAsImage()
2023-12-29 11:17:37 +01:00
}
}
}