If the user clicks the button while editing the TextField (cursor flashing) in DataPtView, the app crashes.
In a list cell, I have the button, which impacts the view that is also shown in the cell. Here's a snippet, iPad specific.
CellView:
VStack{
Button("TagOut"){
self.tagOut.toggle()
}
if self.tagOut {
TagOutView(question: question)
}
if !self.tagOut{
if question.type == "Y/N"{
YesOrNoView(question: question)
} else if question.type == "DataPt"{
DataPtView(question: question)
} else {
RecordEntryView()
}
...
DataPtView:
...
TextField("Data: ", text: $collectedData)
.onReceive(Just(collectedData)) {value in
let filtered = value.filter {"01234567890-".contains($0)}
if filtered != value{
self.invalidCollectedData = true
} else {
self.invalidCollectedData = false
}
}
...
I'm also using an AdaptsToKeyboard ViewModifier for when CellView is covered by the keyboard. move-textfield-up-when-the-keyboard-has-appeared-in-swiftu
How do I prevent this from happening? If user hides the keyboard before clicking the button, everything is fine, but that isn't intuitive.