Not sure if this is a bug or if I'm doing something wrong but if I use:
.toolbar {
ToolbarItemGroup(placement: .navigationBarLeading) {
if isFocused == .zipCode {
Text("Test")
}
}
}
When the field equaling zipCode is focused, my text shows up. However, if I do the same thing but use placement: .keyboard is does not, unless I also provide an additional view like this:
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
if isFocused == .zipCode {
Text("Test")
}
Text("Default")
}
}
If I do that, I get the word Default on every keyboard and then on my zipCode field where the keyboard changes to a numberPad it shows Default Test.
I am trying to add a keyboard toolbar item only to the numberPad keyboard. I tried modifying the conditional to be TextField.keyboardType == .numberPad but you can't do that, nor could I get UIKeyboardType == .numberPad to work.
This form has multiple fields and I only want to add a button if the numberPad keyboard is shown. I do not want to add anything if other keyboard types are shown.
This is for SwiftUI (latest) with iOS 15.