I am trying to make sure I have a consistent animation throughout this dynamic Text view as I'm typing in the TextField.
import SwiftUI
struct ContentView: View {
@ObservedObject var viewModel = ContentViewModel()
var body: some View {
VStack {
HStack {
Text("Write this word: ")
Text(String(viewModel.textValue))
}
TextField("Write here:", text: $viewModel.enteredTextValue)
.padding(10)
.border(Color.green, width: 1)
Text(viewModel.enteredTextValue)
.animation(.easeIn(duration: 0.5)) // added animation here.
Toggle(isOn: $viewModel.textsMatch) {
Text("Matching?")
}
.disabled(true)
.padding()
}.padding()
}
}
class ContentViewModel: ObservableObject {
@Published var textValue: String = "Hello"
@Published var enteredTextValue: String = "" {
didSet {
textsMatch = (enteredTextValue == textValue)
}
}
@Published var textsMatch: Bool = false
}
Notice the animation is smooth in the fist line and then drops at second line?
Would appreciate any help on this please.
FYI code taken from here (Combine framework).
Many thanks!