Any idea why if I tap on Field 1
and immediately after I tap on Field 5
, Field 5
gets hidden by the keyboard?
To replicate my issue, copy and paste the code below, run it in the simulator and make sure the Toggle Software Keybaord is checked, then go and tap on Field 1
and then on Field 5
.
I tried wrapping the fields in a List
and I got the same result.
It almost feels like a bug. The issue seems to occur when moving from the regular .default
keyboard type to the .decimalPad
keyboard.
import SwiftUI
struct TextFieldScrollingIssue: View {
@State private var testInput:String = ""
@State private var decimalInput:String = ""
var body: some View {
VStack{
Form {
TextField("Field 1", text:$testInput)
.id("Field 1")
.keyboardType(.default)
Spacer()
Spacer()
Spacer()
Spacer()
Spacer()
Spacer()
Section(header: Text("Section 2: ")) {
TextField("Field 2", text:$testInput)
.id("Field 2")
.keyboardType(.decimalPad)
TextField("Field 3", text:$decimalInput)
.id("Field 3")
.keyboardType(.decimalPad)
}
Section(header: Text("Section 3: ")) {
TextField("Field 4", text:$testInput)
.id("Field 4")
.keyboardType(.default)
TextField("Field 5", text:$decimalInput)
.id("Field 5")
.keyboardType(.decimalPad)
}
}
}
}
}
struct TextFieldScrollingIssue_Previews: PreviewProvider {
static var previews: some View {
TextFieldScrollingIssue()
}
}