diff --git a/Note/FormatterView.swift b/Note/FormatterView.swift index 9b398de..078a315 100644 --- a/Note/FormatterView.swift +++ b/Note/FormatterView.swift @@ -9,21 +9,19 @@ import SwiftUI struct FormatterView: View { @State private var inputText: String = "" - @State private var outputText: String = "" @State private var showEmptyAlert: Bool = false @State private var showCopied: Bool = false var body: some View { NavigationStack { - List { - inputSection - actionSection - if !outputText.isEmpty { - resultSection - } + VStack(spacing: 0) { + headerView + + inputArea + .frame(maxHeight: .infinity) + + actionArea } - .listStyle(.insetGrouped) - .navigationTitle("文案格式化") .background(Color(.systemGroupedBackground).ignoresSafeArea()) .alert("提示", isPresented: $showEmptyAlert) { Button("确定", role: .cancel) {} @@ -46,15 +44,51 @@ struct FormatterView: View { .transition(.opacity) } } + .navigationBarHidden(true) } } - private var inputSection: some View { - Section { + private var headerView: some View { + HStack { + Text("文案格式化") + .font(.largeTitle.bold()) + .foregroundStyle(.primary) + Spacer() + if !inputText.isEmpty { + Button(action: copyText) { + Image(systemName: "doc.on.doc") + } + .font(.title3) + } + } + .frame(maxWidth: .infinity, minHeight: 44) + .padding(.horizontal) + .padding(.top, 8) + .padding(.bottom, 8) + .background(Color(.systemGroupedBackground)) + .contentShape(Rectangle()) + .onTapGesture { + dismissKeyboard() + } + } + + private var inputArea: some View { + VStack(alignment: .leading, spacing: 8) { + Text("输入") + .font(.subheadline) + .foregroundStyle(.secondary) + .padding(.horizontal) + TextEditor(text: $inputText) - .frame(minHeight: 160) - .scrollContentBackground(.hidden) - .background(Color(.secondarySystemGroupedBackground)) + .frame(maxWidth: .infinity, maxHeight: .infinity) + .padding(12) + .background(Color(.systemBackground)) + .cornerRadius(12) + .overlay( + RoundedRectangle(cornerRadius: 12) + .stroke(Color(.systemGray4), lineWidth: 1) + ) + .padding(.horizontal) .toolbar { ToolbarItemGroup(placement: .keyboard) { Spacer() @@ -63,42 +97,27 @@ struct FormatterView: View { } } } - } header: { - Text("输入") - } footer: { + Text("粘贴需要格式化的文案") - } - } - - private var actionSection: some View { - Section { - Button(action: formatText) { - HStack { - Spacer() - Label("格式化", systemImage: "wand.and.stars") - .font(.headline) - Spacer() - } - } - } - } - - private var resultSection: some View { - Section { - TextEditor(text: .constant(outputText)) - .frame(minHeight: 160) - .scrollContentBackground(.hidden) - .background(Color(.secondarySystemGroupedBackground)) - } header: { - HStack { - Text("格式化结果") - Spacer() - Button(action: copyOutput) { - Image(systemName: "doc.on.doc") - } .font(.subheadline) - } + .foregroundStyle(.secondary) + .padding(.horizontal) } + .padding(.vertical, 8) + } + + private var actionArea: some View { + Button(action: formatText) { + Label("格式化", systemImage: "wand.and.stars") + .font(.headline) + .frame(maxWidth: .infinity) + .padding() + .background(Color(.systemBackground)) + .foregroundStyle(Color.accentColor) + .cornerRadius(12) + } + .padding() + .background(Color(.systemGroupedBackground)) } private func dismissKeyboard() { @@ -108,7 +127,6 @@ struct FormatterView: View { private func formatText() { if inputText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { showEmptyAlert = true - outputText = "" return } @@ -142,12 +160,12 @@ struct FormatterView: View { content = content.replacingOccurrences(of: "二、交易方面", with: "## 二、交易方面") content = content.replacingOccurrences(of: "三、工作方面", with: "## 三、工作方面") - outputText = content + inputText = content dismissKeyboard() } - private func copyOutput() { - UIPasteboard.general.string = outputText + private func copyText() { + UIPasteboard.general.string = inputText withAnimation { showCopied = true }