Add animated gif support (#825)

This commit is contained in:
Stefan Ceriu
2023-04-24 17:44:58 +03:00
committed by GitHub
parent 50f674a111
commit 5a14c700cc
10 changed files with 157 additions and 65 deletions
@@ -20,6 +20,8 @@ protocol ImageProviderProtocol {
func imageFromSource(_ source: MediaSourceProxy?, size: CGSize?) -> UIImage?
func loadImageFromSource(_ source: MediaSourceProxy, size: CGSize?) async -> Result<UIImage, MediaProviderError>
func loadImageDataFromSource(_ source: MediaSourceProxy) async -> Result<Data, MediaProviderError>
}
extension ImageProviderProtocol {
@@ -79,6 +79,16 @@ struct MediaProvider: MediaProviderProtocol {
}
}
func loadImageDataFromSource(_ source: MediaSourceProxy) async -> Result<Data, MediaProviderError> {
do {
let imageData = try await mediaLoader.loadMediaContentForSource(source)
return .success(imageData)
} catch {
MXLog.error("Failed retrieving image with error: \(error)")
return .failure(.failedRetrievingImage)
}
}
// MARK: Files
func loadFileFromSource(_ source: MediaSourceProxy) async -> Result<MediaFileHandleProxy, MediaProviderError> {
@@ -38,6 +38,15 @@ struct MockMediaProvider: MediaProviderProtocol {
return .success(image)
}
func loadImageDataFromSource(_ source: MediaSourceProxy) async -> Result<Data, MediaProviderError> {
guard let image = UIImage(systemName: "photo"),
let data = image.pngData() else {
fatalError()
}
return .success(data)
}
func loadFileFromSource(_ source: MediaSourceProxy) async -> Result<MediaFileHandleProxy, MediaProviderError> {
.failure(.failedRetrievingFile)
}