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
@@ -25,12 +25,10 @@ struct ImageRoomTimelineView: View {
TimelineStyler(timelineItem: timelineItem) {
LoadableImage(mediaSource: timelineItem.source,
blurhash: timelineItem.blurhash,
imageProvider: context.imageProvider) { image in
image.overlay { overlay }
} placeholder: {
imageProvider: context.imageProvider) {
placeholder
}
.frame(maxHeight: 300)
.frame(maxHeight: min(300, timelineItem.height ?? .infinity))
.aspectRatio(timelineItem.aspectRatio, contentMode: .fit)
}
}
@@ -45,20 +43,6 @@ struct ImageRoomTimelineView: View {
.frame(maxWidth: .infinity)
}
}
@ViewBuilder
var overlay: some View {
if timelineItem.contentType == .gif {
Text(L10n.commonGif)
.font(.element.bodyBold)
.foregroundStyle(.primary)
.padding(.horizontal, 10)
.padding(.vertical, 7)
.background(.thinMaterial)
.cornerRadius(8)
.environment(\.colorScheme, .dark)
}
}
}
struct ImageRoomTimelineView_Previews: PreviewProvider {
@@ -77,7 +61,7 @@ struct ImageRoomTimelineView_Previews: PreviewProvider {
isOutgoing: false,
isEditable: false,
sender: .init(id: "Bob"),
source: nil))
source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/png")))
ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: UUID().uuidString,
body: "Some other image",
@@ -85,7 +69,7 @@ struct ImageRoomTimelineView_Previews: PreviewProvider {
isOutgoing: false,
isEditable: false,
sender: .init(id: "Bob"),
source: nil))
source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/png")))
ImageRoomTimelineView(timelineItem: ImageRoomTimelineItem(id: UUID().uuidString,
body: "Blurhashed image",
@@ -93,7 +77,7 @@ struct ImageRoomTimelineView_Previews: PreviewProvider {
isOutgoing: false,
isEditable: false,
sender: .init(id: "Bob"),
source: nil,
source: MediaSourceProxy(url: .picturesDirectory, mimeType: "image/gif"),
aspectRatio: 0.7,
blurhash: "L%KUc%kqS$RP?Ks,WEf8OlrqaekW",
contentType: .gif))
@@ -28,7 +28,7 @@ struct StickerRoomTimelineView: View {
imageProvider: context.imageProvider) {
placeholder
}
.frame(maxHeight: 300)
.frame(maxHeight: min(300, timelineItem.height ?? .infinity))
.aspectRatio(timelineItem.aspectRatio, contentMode: .fit)
}
.accessibilityLabel(timelineItem.body)
@@ -23,7 +23,16 @@ struct VideoRoomTimelineView: View {
var body: some View {
TimelineStyler(timelineItem: timelineItem) {
LoadableImage(mediaSource: timelineItem.thumbnailSource,
thumbnail
.frame(maxHeight: min(300, timelineItem.height ?? .infinity))
.aspectRatio(timelineItem.aspectRatio, contentMode: .fit)
}
}
@ViewBuilder
var thumbnail: some View {
if let thumbnailSource = timelineItem.thumbnailSource {
LoadableImage(mediaSource: thumbnailSource,
blurhash: timelineItem.blurhash,
imageProvider: context.imageProvider) { imageView in
imageView
@@ -31,8 +40,8 @@ struct VideoRoomTimelineView: View {
} placeholder: {
placeholder
}
.frame(maxHeight: 300)
.aspectRatio(timelineItem.aspectRatio, contentMode: .fit)
} else {
playIcon
}
}