From 3c5a34b20966dcc01fecc9952cb259e1afcaf1d4 Mon Sep 17 00:00:00 2001 From: Ivan Magda Date: Fri, 26 Jul 2024 17:04:46 +0900 Subject: [PATCH] ALTAPPS-1272: Fix HackerTextView contains incorrect symbols after animation is completed --- .../SwiftUI/TextEffects/HackerTextView.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/iosHyperskillApp/iosHyperskillApp/Sources/Views/SwiftUI/TextEffects/HackerTextView.swift b/iosHyperskillApp/iosHyperskillApp/Sources/Views/SwiftUI/TextEffects/HackerTextView.swift index 4e68639a22..877e867924 100644 --- a/iosHyperskillApp/iosHyperskillApp/Sources/Views/SwiftUI/TextEffects/HackerTextView.swift +++ b/iosHyperskillApp/iosHyperskillApp/Sources/Views/SwiftUI/TextEffects/HackerTextView.swift @@ -28,6 +28,7 @@ struct HackerTextView: View { setRandomCharacters() animateText() + applyFinalTextCharacters() } .onChange(of: text) { _ in animatedText = text @@ -35,6 +36,7 @@ struct HackerTextView: View { setRandomCharacters() animateText() + applyFinalTextCharacters() } } @@ -95,6 +97,20 @@ struct HackerTextView: View { animatedText.replaceSubrange(index...index, with: String(character)) } } + + private func applyFinalTextCharacters() { + let currentID = animationID + + DispatchQueue.main.asyncAfter(deadline: .now() + duration) { + guard currentID == animationID else { + return + } + + if animatedText != text { + animatedText = text + } + } + } } #if DEBUG