Hello developers !
I've created a List or a ForEach from a binding where there are TextFields or TextEditors inside. When I go to fill in the text, the keyboard dismisses after one char is typed in !
My need is to be able to add textfields as much as required.
Please have a look to this code
import SwiftUI
struct ContentView: View {
@State private var messages = ["Hello 1","Hello 2","Hello 3"]
var body: some View {
VStack(alignment: .leading) {
List($messages, id: \.self) { $msg in
TextEditor(text: $msg)
}
ForEach($messages, id: \.self) { $msg in
VStack{
TextEditor(text: $msg)
}
.contextMenu{
Button(role: .destructive, action: {
messages = messages.filter {$0 != msg}
}, label:{
Text("Delete entry")
})
}
}
Button(action: {
messages.append("-")
}
, label: {
Text("Add a row")
})
}
.background(.black)
.padding()
}
}
#Preview {
ContentView()
}
I'm using iOS 17.4 and Xcode 15.3 Thanks !