对齐有线传图页 Android UI,并改用相对路径持久化本地照片。
还原顶栏、浮动卡片、时间侧栏与底部交互;照片路径改为 CameraDownloads 相对路径并兼容旧数据;格式 Chip 固定 JPG 且不可点击。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -0,0 +1,63 @@
|
||||
//
|
||||
// WiredTransferPhotoPreviewSheet.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
import Kingfisher
|
||||
|
||||
/// 有线传图照片预览,支持本地 file:// 与远程 URL。
|
||||
struct WiredTransferPhotoPreviewSheet: View {
|
||||
let imageSources: [String]
|
||||
let startIndex: Int
|
||||
let onDismiss: () -> Void
|
||||
|
||||
@State private var currentIndex: Int
|
||||
|
||||
init(imageSources: [String], startIndex: Int, onDismiss: @escaping () -> Void) {
|
||||
self.imageSources = imageSources
|
||||
self.startIndex = startIndex
|
||||
self.onDismiss = onDismiss
|
||||
_currentIndex = State(initialValue: startIndex)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
TabView(selection: $currentIndex) {
|
||||
ForEach(Array(imageSources.enumerated()), id: \.offset) { index, source in
|
||||
previewImage(source)
|
||||
.tag(index)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.background(Color.black)
|
||||
}
|
||||
}
|
||||
.tabViewStyle(.page(indexDisplayMode: imageSources.count > 1 ? .automatic : .never))
|
||||
.background(Color.black.ignoresSafeArea())
|
||||
.navigationTitle("图片预览")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button("关闭", action: onDismiss)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func previewImage(_ source: String) -> some View {
|
||||
if source.hasPrefix("file://"), let url = URL(string: source),
|
||||
let uiImage = UIImage(contentsOfFile: url.path) {
|
||||
Image(uiImage: uiImage)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
} else if let url = URL(string: source), !source.isEmpty {
|
||||
KFImage(url)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
} else {
|
||||
Text("暂无法预览该照片")
|
||||
.foregroundStyle(.white.opacity(0.8))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user