46 lines
885 B
Swift
46 lines
885 B
Swift
import SwiftUI
|
|
|
|
struct TextEntrySheet: View {
|
|
|
|
let title: String
|
|
|
|
@Binding
|
|
var text: String
|
|
|
|
@Environment(\.dismiss)
|
|
var dismiss: DismissAction
|
|
|
|
@State
|
|
private var enteredText: String = ""
|
|
|
|
var body: some View {
|
|
VStack {
|
|
Text(title)
|
|
.foregroundStyle(.secondary)
|
|
TextField("Text", text: $enteredText)
|
|
HStack {
|
|
Button(action: submit) {
|
|
Text("Submit")
|
|
}
|
|
Button(role: .cancel, action: cancel) {
|
|
Text("Cancel")
|
|
}
|
|
}
|
|
}
|
|
.padding()
|
|
}
|
|
|
|
private func submit() {
|
|
text = enteredText
|
|
dismiss()
|
|
}
|
|
|
|
private func cancel() {
|
|
dismiss()
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
TextEntrySheet(title: "Enter the id for the new post", text: .constant("new"))
|
|
}
|