Add iOS media placeholders
This commit is contained in:
@@ -657,6 +657,9 @@ public struct MessageRow: View {
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
if let media = message.media {
|
||||
MediaPlaceholderView(media: media, mediaAlbumId: message.mediaAlbumId)
|
||||
}
|
||||
Text(renderedText)
|
||||
.textSelection(.enabled)
|
||||
if !message.reactions.isEmpty {
|
||||
@@ -706,6 +709,81 @@ public struct MessageRow: View {
|
||||
}()
|
||||
}
|
||||
|
||||
public struct MediaPlaceholderView: View {
|
||||
public var media: MessageMedia
|
||||
public var mediaAlbumId: Int64?
|
||||
|
||||
public init(media: MessageMedia, mediaAlbumId: Int64? = nil) {
|
||||
self.media = media
|
||||
self.mediaAlbumId = mediaAlbumId
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: iconName)
|
||||
.frame(width: 22, height: 22)
|
||||
.foregroundStyle(.blue)
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
HStack(spacing: 6) {
|
||||
Text(title)
|
||||
.font(.subheadline)
|
||||
if mediaAlbumId != nil {
|
||||
Image(systemName: "square.stack.3d.up.fill")
|
||||
.font(.caption2)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
Text(detail)
|
||||
.font(.caption2)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.padding(8)
|
||||
.background(Color.gray.opacity(0.10), in: RoundedRectangle(cornerRadius: 8))
|
||||
}
|
||||
|
||||
private var iconName: String {
|
||||
switch media {
|
||||
case .photo:
|
||||
"photo"
|
||||
case .voice:
|
||||
"waveform"
|
||||
}
|
||||
}
|
||||
|
||||
private var title: String {
|
||||
switch media {
|
||||
case .photo:
|
||||
"Photo"
|
||||
case .voice:
|
||||
"Voice"
|
||||
}
|
||||
}
|
||||
|
||||
private var detail: String {
|
||||
switch media {
|
||||
case let .photo(photo):
|
||||
"\(photo.width)x\(photo.height) · \(downloadLabel(photo.downloadState))"
|
||||
case let .voice(voice):
|
||||
"\(voice.duration)s · \(downloadLabel(voice.downloadState))"
|
||||
}
|
||||
}
|
||||
|
||||
private func downloadLabel(_ state: MediaDownloadState) -> String {
|
||||
switch state {
|
||||
case .notDownloaded:
|
||||
"not downloaded"
|
||||
case .downloading:
|
||||
"downloading"
|
||||
case .downloaded:
|
||||
"downloaded"
|
||||
case .error:
|
||||
"error"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct ComposeBar: View {
|
||||
@Binding public var text: String
|
||||
public var replyTo: Message?
|
||||
|
||||
Reference in New Issue
Block a user