I have a Text view that acts as a button. When the user taps it it has to disable a TextField.
I set the boolean variable that enables and disables the TextField, inside an .onTapGesture() modifier. I did that so the state of the variable wasn't being modified directly inside the body of a view, which is what would cause the error.
However, I'm still getting the error when I tap on the Text view.
Commenting out "answerDisabled = true", stops the error but obviously doesn't disable the TextField.
Text("Show next time")
.font(.system(size: buttonFontSize, weight: .heavy, design: .rounded))
.padding()
.background(RoundedRectangle(cornerRadius: 10, style:
.continuous).fill(showNextTimeDisabled ? .gray : Color.systemBlue))
.foregroundColor(.white)
.opacity(showNextTimeDisabled ? 0.8 : 1.0)
.disabled(showNextTimeDisabled)
.frame(width: geometry.size.width * buttonWidthScale, height: geometry.size.height * buttonHeightScale)
.position(x: geometry.frame(in: .local).midX + geometry.size.width / 3.9, y: geometry.frame(in: .local).midY + geometry.size.height / 26)
.onTapGesture {
spacedRepetition.decreaseTestsUntilPresented(currentQuestion: testSectionThings?[questionCounter] ?? SectionThing())
showNextTimeDisabled = true
iKnowThisDisabled = true
answerDisabled = true
skipDisabled = false
if answered {
testSectionThings?[questionCounter].correctAnswers = 0
testSectionThings?[questionCounter].attempts += 1
PersistenceController.shared.saveDB()
}
if wrongAnswer.isEmpty {
let separator = NSMutableAttributedString(string: " ", attributes: noTestSectionThingsAttributes)
let tapAttributedString = NSMutableAttributedString(string: "Tap ", attributes: noTestSectionThingsAttributes)
let skipImageAttachment = NSTextAttachment()
skipImageAttachment.image = UIImage(named: "skip.png")?.withTintColor(.systemBlue)
let skipImageAttributedString = NSMutableAttributedString(attachment: skipImageAttachment)
let nextQuestionAttributedString = NSMutableAttributedString(string: NSLocalizedString(" for next question.", comment: "Answer field tap skip 2"), attributes: noTestSectionThingsAttributes)
let NSMutableAttributedStringArray = [tapAttributedString, skipImageAttributedString, nextQuestionAttributedString]
nativeForeignPlaceholder = NSMutableAttributedStringArray.join(withSeparator: separator)
}
}