I have a stack of cards, each card having a TextField, when focus a text field positioned at the bottom of the screen (on the area where the keyboard will appear) the card disappears, thus the keyboard disappears as well.
I expect that the field is focused and scrolled automatically to the visible area.
I found that the "Submit" button I have fixed at the bottom of the screen is causing the issue, so it works fine if I remove it.
Another solution would be to use VStack instead of LazyVStack but I really need this Lazy behaviour since there can be lots of cards
struct ContentView: View {
@State private var text: String = ""
var body: some View {
VStack {
ScrollView {
LazyVStack {
ForEach(0..<200, id: \.self) { _ in
CardView()
}
}
}
Button("Submit") { }
.frame(maxWidth: .infinity)
.background(Color.white)
}.background(Color.secondary)
}
}
struct CardView: View {
@State private var text: String = ""
var body: some View {
TextField("text", text: $text)
.frame(height: 50, alignment: .leading)
.background(Color.white)
}
}

LazyVStackin aScrollView. Works well without theLazyVStack. See also: stackoverflow.com/questions/66523786/…