fix: 优化任务详情与图片预览布局

This commit is contained in:
2026-08-18 16:41:55 +08:00
parent c34c4e1923
commit 1757ba5e36
3 changed files with 237 additions and 74 deletions
@@ -91,7 +91,15 @@ final class TravelAlbumPhotoPreviewViewController: UIViewController {
self.allowsActions = allowsActions
super.init(nibName: nil, bundle: nil)
modalPresentationStyle = .fullScreen
rebuildNodes(keepingProjectIndex: max(0, min(startProjectIndex, projects.count - 1)), kind: startKind)
let resolvedProjectIndex = max(0, min(startProjectIndex, self.projects.count - 1))
let initialProject = self.projects.indices.contains(resolvedProjectIndex)
? self.projects[resolvedProjectIndex]
: nil
let resolvedStartKind = initialProject?.asset(for: startKind) == nil
? initialProject?.orderedAssets.first?.kind ?? .original
: startKind
selectedKind = resolvedStartKind
rebuildNodes(keepingProjectIndex: resolvedProjectIndex, kind: resolvedStartKind)
}
@available(*, unavailable)
@@ -165,6 +173,7 @@ final class TravelAlbumPhotoPreviewViewController: UIViewController {
sizeLabel.textColor = UIColor.white.withAlphaComponent(0.52)
sizeLabel.font = .systemFont(ofSize: 13, weight: .regular)
sizeLabel.textAlignment = .center
sizeLabel.accessibilityIdentifier = "travelAlbum.previewFileSizeLabel"
counterLabel.textColor = UIColor.white.withAlphaComponent(0.82)
counterLabel.font = .monospacedDigitSystemFont(ofSize: 15, weight: .medium)
@@ -423,7 +432,9 @@ final class TravelAlbumPhotoPreviewViewController: UIViewController {
guard let node = currentNode else { return }
let asset = currentAsset
titleLabel.text = asset?.fileName.isEmpty == false ? asset?.fileName : "未命名照片"
sizeLabel.text = TravelAlbumDisplayFormatter.fileSizeText(asset?.fileSize ?? 0)
let fileSize = asset?.fileSize ?? 0
sizeLabel.text = fileSize > 0 ? TravelAlbumDisplayFormatter.fileSizeText(fileSize) : nil
sizeLabel.isHidden = fileSize <= 0
counterLabel.text = "\(node.projectIndex + 1)/\(max(totalCount, projects.count))"
counterLabel.accessibilityLabel = "第 \(node.projectIndex + 1) 张,共 \(max(totalCount, projects.count)) 张"
highResolutionButton.isEnabled = asset != nil
@@ -982,6 +993,56 @@ extension TravelAlbumPhotoPreviewViewController: UICollectionViewDataSource, UIC
}
}
/// 深色图片预览中使用的高对比度延迟加载指示器。
@MainActor
private final class TravelAlbumPreviewLoadingIndicator: Indicator {
private let containerView = UIView()
private let activityIndicator = UIActivityIndicatorView(style: .medium)
private var revealTask: Task<Void, Never>?
var view: IndicatorView { containerView }
init() {
containerView.backgroundColor = UIColor(red: 39 / 255, green: 39 / 255, blue: 42 / 255, alpha: 0.94)
containerView.layer.cornerRadius = 22
containerView.isAccessibilityElement = true
containerView.accessibilityIdentifier = "travelAlbum.previewLoadingIndicator"
containerView.accessibilityLabel = "图片加载中"
activityIndicator.color = UIColor.white.withAlphaComponent(0.92)
activityIndicator.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
containerView.addSubview(activityIndicator)
activityIndicator.snp.makeConstraints { $0.center.equalToSuperview() }
}
func startAnimatingView() {
revealTask?.cancel()
containerView.alpha = 0
containerView.isHidden = true
revealTask = Task { @MainActor [weak self] in
try? await Task.sleep(for: .milliseconds(150))
guard !Task.isCancelled, let self else { return }
activityIndicator.startAnimating()
containerView.isHidden = false
UIView.animate(
withDuration: UIAccessibility.isReduceMotionEnabled ? 0 : 0.12,
animations: { self.containerView.alpha = 1 }
)
}
}
func stopAnimatingView() {
revealTask?.cancel()
revealTask = nil
activityIndicator.stopAnimating()
containerView.alpha = 0
containerView.isHidden = true
}
func sizeStrategy(in imageView: KFCrossPlatformImageView) -> IndicatorSizeStrategy {
.size(CGSize(width: 44, height: 44))
}
}
/// 预览图片 Cell,使用 UIScrollView 提供远程加载、双击和双指缩放。
private final class TravelAlbumPreviewImageCell: UICollectionViewCell, UIScrollViewDelegate {
static let reuseIdentifier = "TravelAlbumPreviewImageCell"
@@ -1054,7 +1115,7 @@ private final class TravelAlbumPreviewImageCell: UICollectionViewCell, UIScrollV
imageView.contentMode = .scaleAspectFit
imageView.backgroundColor = .black
imageView.kf.indicatorType = .activity
imageView.kf.indicatorType = .custom(indicator: TravelAlbumPreviewLoadingIndicator())
imageView.accessibilityIdentifier = "travelAlbum.previewImageView"
retryButton.setTitle("图片加载失败,点击重试", for: .normal)