空文案时弹出提示不跳转
This commit is contained in:
@@ -10,6 +10,7 @@ import SwiftUI
|
|||||||
struct FormatterView: View {
|
struct FormatterView: View {
|
||||||
@State private var inputText: String = ""
|
@State private var inputText: String = ""
|
||||||
@State private var resultText: String?
|
@State private var resultText: String?
|
||||||
|
@State private var showEmptyAlert: Bool = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
@@ -41,10 +42,19 @@ struct FormatterView: View {
|
|||||||
.navigationDestination(item: $resultText) { text in
|
.navigationDestination(item: $resultText) { text in
|
||||||
ResultView(formattedText: text)
|
ResultView(formattedText: text)
|
||||||
}
|
}
|
||||||
|
.alert("提示", isPresented: $showEmptyAlert) {
|
||||||
|
Button("确定", role: .cancel) {}
|
||||||
|
} message: {
|
||||||
|
Text("请输入需要格式化的文案")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func formatAndNavigate() {
|
private func formatAndNavigate() {
|
||||||
|
if inputText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
||||||
|
showEmptyAlert = true
|
||||||
|
return
|
||||||
|
}
|
||||||
resultText = format(inputText)
|
resultText = format(inputText)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user