In a SwiftUI List, when switching from a default keyboard to decimalPad keyboard, the List scrolls down unnecessarily and the focused textfield is hidden by keyboard.
struct ListTextField: View {
@State private var focusedFieldID: Int?
@FocusState private var focusedField: Int?
var body: some View {
ScrollViewReader { proxy in
List {
ForEach(0 ..< 12) { index in
Group {
TextField("Name", text: .constant(""))
.id(index * 2)
.focused($focusedField, equals: index * 2)
TextField("id", value: .constant(index), format: .number)
.keyboardType(.decimalPad)
.font(.body)
.id(index * 2 + 1)
.focused($focusedField, equals: index * 2 + 1)
}
}
}
}
}
}
The list should maintain its current scroll position when switching focus to the decimalPad TextField, just like it does for default keyboards.
I tried replacing the List with a ScrollView, and while it works fine functionally, I still need the swipe-to-delete and move/reorder actions that List provides.