* Use the new TimelineMediaPreview modifier on the room and pinned timeline screens. * Use the same presentation logic for all timeline media previews. * Fix a bug with the detection of the timeline end. * Send pagination requests from the media preview screen. * Add SwiftLint to the Danger workflow (it is no longer installed on the runner). * Put SwiftLint back on all of the GitHub runners too. * Set the function_parameter_count lint rule to 10. * Make sure to clean-up any previews when the coordinator is done. * Handle the viewInRoomTimeline action more appropriately.
83 lines
2.4 KiB
Swift
83 lines
2.4 KiB
Swift
//
|
|
// Copyright 2024 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 Combine
|
|
import SwiftUI
|
|
|
|
enum TimelineMediaPreviewViewModelAction: Equatable {
|
|
case viewInRoomTimeline(TimelineItemIdentifier)
|
|
case dismiss
|
|
}
|
|
|
|
enum TimelineMediaPreviewDriverAction {
|
|
case itemLoaded(TimelineItemIdentifier.EventOrTransactionID)
|
|
case showItemDetails(TimelineMediaPreviewItem.Media)
|
|
case exportFile(TimelineMediaPreviewFileExportPicker.File)
|
|
case authorizationRequired(appMediator: AppMediatorProtocol)
|
|
case dismissDetailsSheet
|
|
|
|
var isItemLoaded: Bool {
|
|
switch self {
|
|
case .itemLoaded: true
|
|
default: false
|
|
}
|
|
}
|
|
|
|
var isShowItemDetails: Bool {
|
|
switch self {
|
|
case .showItemDetails: true
|
|
default: false
|
|
}
|
|
}
|
|
|
|
var isExportFile: Bool {
|
|
switch self {
|
|
case .exportFile: true
|
|
default: false
|
|
}
|
|
}
|
|
|
|
var isAuthorizationRequired: Bool {
|
|
switch self {
|
|
case .authorizationRequired: true
|
|
default: false
|
|
}
|
|
}
|
|
}
|
|
|
|
struct TimelineMediaPreviewViewState: BindableState {
|
|
/// The data source for all of the preview-able items.
|
|
var dataSource: TimelineMediaPreviewDataSource
|
|
|
|
/// The media item that is currently being previewed.
|
|
var currentItem: TimelineMediaPreviewItem { dataSource.currentItem }
|
|
/// All of the available actions for the current item.
|
|
var currentItemActions: TimelineItemMenuActions?
|
|
|
|
/// A publisher that the view model uses to signal actions to the QLPreviewController.
|
|
let previewControllerDriver = PassthroughSubject<TimelineMediaPreviewDriverAction, Never>()
|
|
|
|
var bindings = TimelineMediaPreviewViewStateBindings()
|
|
}
|
|
|
|
struct TimelineMediaPreviewViewStateBindings {
|
|
/// A binding that will present a confirmation to redact the specified item.
|
|
var redactConfirmationItem: TimelineMediaPreviewItem.Media?
|
|
}
|
|
|
|
enum TimelineMediaPreviewAlertType {
|
|
case authorizationRequired
|
|
}
|
|
|
|
enum TimelineMediaPreviewViewAction {
|
|
case updateCurrentItem(TimelineMediaPreviewItem)
|
|
case showItemDetails(TimelineMediaPreviewItem.Media)
|
|
case menuAction(TimelineItemMenuAction, item: TimelineMediaPreviewItem.Media)
|
|
case redactConfirmation(item: TimelineMediaPreviewItem.Media)
|
|
case timelineEndReached
|
|
}
|