Added blurhash and correct sizes to timeline images and animations throughout the app.

This commit is contained in:
Stefan Ceriu
2022-04-05 15:09:04 +03:00
parent 88a0654d23
commit 8d50d4fd25
9 changed files with 233 additions and 11 deletions
@@ -6,7 +6,7 @@
// Copyright © 2022 Element. All rights reserved.
//
import Foundation
import UIKit
import MatrixRustSDK
struct ImageRoomMessage: RoomMessageProtocol {
@@ -35,4 +35,24 @@ struct ImageRoomMessage: RoomMessageProtocol {
var url: String? {
message.url()
}
var width: CGFloat? {
guard let width = message.width() else {
return nil
}
return CGFloat(width)
}
var height: CGFloat? {
guard let height = message.height() else {
return nil
}
return CGFloat(height)
}
var blurhash: String? {
message.blurhash()
}
}
@@ -21,4 +21,9 @@ struct ImageRoomTimelineItem: EventBasedTimelineItemProtocol, Identifiable, Equa
let url: String?
var image: UIImage?
var width: CGFloat?
var height: CGFloat?
var aspectRatio: CGFloat?
var blurhash: String?
}
@@ -63,6 +63,13 @@ struct RoomTimelineItemFactory {
_ showSenderDetails: Bool,
_ displayName: String?,
_ avatarImage: UIImage?) -> RoomTimelineItemProtocol {
var aspectRatio: CGFloat?
if let width = message.width,
let height = message.height {
aspectRatio = width / height
}
return ImageRoomTimelineItem(id: message.id,
text: message.body,
timestamp: message.originServerTs.formatted(date: .omitted, time: .shortened),
@@ -71,7 +78,11 @@ struct RoomTimelineItemFactory {
senderDisplayName: displayName,
senderAvatar: avatarImage,
url: message.url,
image: mediaProvider.imageForURL(message.url))
image: mediaProvider.imageForURL(message.url),
width: message.width,
height: message.height,
aspectRatio: aspectRatio,
blurhash: message.blurhash)
}
private func buildNoticeTimelineItemFromMessage(_ message: NoticeRoomMessage,