无结果时隐藏格式化结果区域

This commit is contained in:
2026-07-12 16:54:32 +08:00
parent eefb7b2f5c
commit 44660190da
+2 -7
View File
@@ -18,8 +18,10 @@ struct FormatterView: View {
List { List {
inputSection inputSection
actionSection actionSection
if !outputText.isEmpty {
resultSection resultSection
} }
}
.listStyle(.insetGrouped) .listStyle(.insetGrouped)
.navigationTitle("文案格式化") .navigationTitle("文案格式化")
.background(Color(.systemGroupedBackground).ignoresSafeArea()) .background(Color(.systemGroupedBackground).ignoresSafeArea())
@@ -83,20 +85,14 @@ struct FormatterView: View {
private var resultSection: some View { private var resultSection: some View {
Section { Section {
if outputText.isEmpty {
Text("点击上方按钮生成格式化结果")
.foregroundStyle(.secondary)
} else {
TextEditor(text: .constant(outputText)) TextEditor(text: .constant(outputText))
.frame(minHeight: 160) .frame(minHeight: 160)
.scrollContentBackground(.hidden) .scrollContentBackground(.hidden)
.background(Color(.secondarySystemGroupedBackground)) .background(Color(.secondarySystemGroupedBackground))
}
} header: { } header: {
HStack { HStack {
Text("格式化结果") Text("格式化结果")
Spacer() Spacer()
if !outputText.isEmpty {
Button(action: copyOutput) { Button(action: copyOutput) {
Image(systemName: "doc.on.doc") Image(systemName: "doc.on.doc")
} }
@@ -104,7 +100,6 @@ struct FormatterView: View {
} }
} }
} }
}
private func dismissKeyboard() { private func dismissKeyboard() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)