格式化后跳转结果页查看
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// 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: "# 示例文本")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user