Skip to content

Commit

Permalink
Fix bug in verifying words interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenperera committed Dec 5, 2024
1 parent bf79dbc commit 9db6721
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ struct VerifyWordsScreen: View {

@MainActor
func deselectWord(_ animation: Animation = .spring(), completion: @escaping () -> Void = {}) {
withAnimation(animation) {
checkState = .none
withAnimation(animation, completionCriteria: .logicallyComplete) {
checkState = .returning
} completion: {
checkState = .none
completion()
}
}
Expand All @@ -191,6 +192,8 @@ struct VerifyWordsScreen: View {
if validator.isComplete(wordNumber: UInt8(wordNumber)) {
withAnimation(.easeInOut(duration: 0.3)) {
verificationComplete = true
} completion: {
checkState = .none
}
return
}
Expand All @@ -199,7 +202,7 @@ struct VerifyWordsScreen: View {
wordNumber += 1
possibleWords = validator.possibleWords(for: UInt8(wordNumber))
} completion: {
deselectWord(.spring().speed(2.5))
checkState = .none
}
}

Expand Down Expand Up @@ -245,7 +248,10 @@ struct VerifyWordsScreen: View {

VStack(spacing: 10) {
if let checkingWord = checkState.word {
Button(action: { deselectWord() }) {
Button(action: {
guard case .checking = checkState else { return }
deselectWord()
}) {
Text(checkingWord)
.font(.caption)
.fontWeight(.medium)
Expand Down Expand Up @@ -372,7 +378,7 @@ struct VerifyWordsScreen: View {
}

enum CheckState: Equatable {
case none, checking(String), correct(String), incorrect(String)
case none, checking(String), correct(String), incorrect(String), returning

var word: String? {
switch self {
Expand All @@ -382,7 +388,7 @@ enum CheckState: Equatable {
word
case let .incorrect(word):
word
case .none:
case .none, .returning:
nil
}
}
Expand Down

0 comments on commit 9db6721

Please sign in to comment.