83 lines
2.3 KiB
Swift
83 lines
2.3 KiB
Swift
//
|
|
// ResultView.swift
|
|
// Note
|
|
//
|
|
// Created by fish on 2026/7/12.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ResultView: View {
|
|
let formattedText: String
|
|
@Environment(\.dismiss) private var dismiss
|
|
@State private var showCopied: Bool = false
|
|
|
|
var body: some View {
|
|
ScrollView {
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
Text(formattedText)
|
|
.font(.body)
|
|
.lineSpacing(4)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.padding()
|
|
.background(Color(.systemGray6))
|
|
.cornerRadius(12)
|
|
|
|
Button(action: copyText) {
|
|
Label("复制结果", systemImage: "doc.on.doc")
|
|
.font(.headline)
|
|
.frame(maxWidth: .infinity)
|
|
.padding()
|
|
.background(Color.accentColor)
|
|
.foregroundStyle(.white)
|
|
.cornerRadius(10)
|
|
}
|
|
}
|
|
.padding()
|
|
}
|
|
.navigationTitle("格式化结果")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .topBarTrailing) {
|
|
Button("完成") {
|
|
dismiss()
|
|
}
|
|
}
|
|
}
|
|
.overlay {
|
|
if showCopied {
|
|
VStack {
|
|
Spacer()
|
|
Text("已复制")
|
|
.font(.subheadline)
|
|
.padding(.horizontal, 16)
|
|
.padding(.vertical, 8)
|
|
.background(Color.black.opacity(0.75))
|
|
.foregroundStyle(.white)
|
|
.cornerRadius(20)
|
|
.padding(.bottom, 32)
|
|
}
|
|
.transition(.opacity)
|
|
}
|
|
}
|
|
}
|
|
|
|
private func copyText() {
|
|
UIPasteboard.general.string = formattedText
|
|
withAnimation {
|
|
showCopied = true
|
|
}
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
|
|
withAnimation {
|
|
showCopied = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
NavigationStack {
|
|
ResultView(formattedText: "# 示例文本")
|
|
}
|
|
}
|