空文案时弹出提示不跳转

This commit is contained in:
2026-07-12 15:58:39 +08:00
parent 193a44f472
commit 34b26eedd6
+10
View File
@@ -10,6 +10,7 @@ import SwiftUI
struct FormatterView: View {
@State private var inputText: String = ""
@State private var resultText: String?
@State private var showEmptyAlert: Bool = false
var body: some View {
NavigationStack {
@@ -41,10 +42,19 @@ struct FormatterView: View {
.navigationDestination(item: $resultText) { text in
ResultView(formattedText: text)
}
.alert("提示", isPresented: $showEmptyAlert) {
Button("确定", role: .cancel) {}
} message: {
Text("请输入需要格式化的文案")
}
}
}
private func formatAndNavigate() {
if inputText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
showEmptyAlert = true
return
}
resultText = format(inputText)
}