SwiftUI - Keyboard gets dismiss after the first character on the second textfield in Form

393 views Asked by At

I have a form with some of the textfields using the default keyboard. In the example below, the first textfield is using numberPad, and the second and third are using the default keyboard. When I try to input any value in the first field, it works fine. But after moving to the second field, the keyboard suddenly dismisses after clicking the first character.

enter image description here

import SwiftUI

struct SettingsForm: View {
    @ObservedObject var model : SettingModel
    
    var body: some View {
        Form {          
            Section {
                TextField("Title", text: $model.title)
                    .autocapitalization(.none)
                    .disableAutocorrection(true)
                    .cornerRadius(8)
                    .keyboardType(.numberPad)
                TextField("Request Signal", text: $model.signal)
                    .autocapitalization(.none)
                    .disableAutocorrection(true)
                    .cornerRadius(8.0)
                TextField("Message", text: $model.message)
                    .autocapitalization(.none)
                    .disableAutocorrection(true)
                    .cornerRadius(8.0)
            } header: {
                Text("DETAILS")
            } footer: {
                if !model.errUserkey.isEmpty {
                    let errMsg = LocalizedString(model.errUserkey)
                    Text(styledLocalizedString: errMsg).foregroundColor(Color.red)
                } else if !model.errRequestSignal.isEmpty {
                    let errMsg = LocalizedString(model.errRequestSignal)
                    Text(styledLocalizedString: errMsg).foregroundColor(Color.red)
                } else if !model.errMessage.isEmpty {
                    let errMsg = LocalizedString(model.errMessage)
                    Text(styledLocalizedString: errMsg).foregroundColor(Color.red)
                }
            }
        }.onAppear {
            UITableView.appearance().backgroundColor = .clear
        }
    }
}

I also tried using @FocusState private var focusedField: FocusedField? for every textfield with the default keyboard, but no difference. This bug doesn't appear if all the textfields are using numberPad.

I tested it using a real device running iOS 16.2 with XCode 14.2 Any ideas or suggestions?

0

There are 0 answers