mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 16:24:11 +00:00
6967f99626
* scan also thumbnails for medias * pr suggestion
80 lines
3.9 KiB
Swift
80 lines
3.9 KiB
Swift
//
|
|
// Copyright 2025 Element Creations Ltd.
|
|
// Copyright 2022-2025 New Vector Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
// Please see LICENSE files in the repository root for full details.
|
|
//
|
|
|
|
import Compound
|
|
import SwiftUI
|
|
|
|
struct FileMediaEventsTimelineView: View {
|
|
@Environment(\.timelineContext) private var context
|
|
|
|
let timelineItem: FileRoomTimelineItem
|
|
|
|
/// Whether the item's media failed content scanning, in which case the bubble adopts
|
|
/// the critical styling. Reported by the `ContentScanningView` through the preference key.
|
|
@State private var contentScanningFailure: ContentScanningFailure?
|
|
|
|
var body: some View {
|
|
MediaFileRoomTimelineContent(filename: timelineItem.content.filename,
|
|
fileSize: timelineItem.content.fileSize,
|
|
caption: timelineItem.content.caption,
|
|
formattedCaption: timelineItem.content.formattedCaption,
|
|
trailingReservedSize: timelineItem.trailingReservedSize,
|
|
contentScannerService: context?.contentScannerService,
|
|
mediaSource: timelineItem.content.source,
|
|
thumbnailSource: timelineItem.content.thumbnailSource)
|
|
.accessibilityLabel(L10n.commonFile)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.bubbleBackground(isOutgoing: timelineItem.isOutgoing,
|
|
color: contentScanningFailure == nil ? .compound.bgSubtleSecondary : .compound.bgCriticalSubtle,
|
|
borderColor: contentScanningFailure == nil ? nil : .compound.borderCriticalSubtle)
|
|
.onPreferenceChange(ContentScanningFailurePreferenceKey.self) { contentScanningFailure = $0 }
|
|
}
|
|
}
|
|
|
|
struct FileMediaEventsTimelineView_Previews: PreviewProvider, TestablePreview {
|
|
static let viewModel = TimelineViewModel.mock
|
|
|
|
static var previews: some View {
|
|
VStack(spacing: 20.0) {
|
|
FileMediaEventsTimelineView(timelineItem: makeItem(filename: "document.pdf"))
|
|
|
|
FileMediaEventsTimelineView(timelineItem: makeItem(filename: "document.pdf",
|
|
fileSize: 3 * 1024 * 1024))
|
|
|
|
FileMediaEventsTimelineView(timelineItem: makeItem(filename: "spreadsheet.xlsx",
|
|
fileSize: 17 * 1024,
|
|
caption: "The important figures you asked me to send over."))
|
|
|
|
FileMediaEventsTimelineView(timelineItem: makeItem(filename: "document.txt",
|
|
fileSize: 456,
|
|
caption: "Plain caption",
|
|
formattedCaption: "Formatted caption"))
|
|
}
|
|
.environmentObject(viewModel.context)
|
|
}
|
|
|
|
static func makeItem(filename: String,
|
|
fileSize: UInt? = nil,
|
|
caption: String? = nil,
|
|
formattedCaption: AttributedString? = nil) -> FileRoomTimelineItem {
|
|
.init(id: .randomEvent,
|
|
timestamp: .mock,
|
|
isOutgoing: false,
|
|
isEditable: false,
|
|
canBeRepliedTo: true,
|
|
sender: .init(id: "Bob"),
|
|
content: .init(filename: filename,
|
|
caption: caption,
|
|
formattedCaption: formattedCaption,
|
|
source: nil,
|
|
fileSize: fileSize,
|
|
thumbnailSource: nil,
|
|
contentType: nil))
|
|
}
|
|
}
|