I would like to add animation so that when I click a button, the text inside my TextEditor (in iOS 14) fades out slowly (let's say with a duration of 1.5).
This is the code I am working with, but cannot get the text to fade out. Any ideas of what I am doing wrong?
struct FadeTextFromTextEditor: View {
@State private var isAnimationOn = true
@State private var text: String = ""
@State private var resetText = true
var body: some View {
VStack(alignment: .center) {
if #available(iOS 14.0, *)
{
TextEditor(text: $text)
.border(Color.black, width: 1)
.padding(.horizontal, 5)
.padding(.vertical, 5)
.animation(.easeOut(duration: 1.5), value: resetText)
}
Button(action : {
// If bool for fading the text out is set to true, use animation on the text
if (self.isAnimationOn) {
withAnimation(.easeOut(duration: 1.5))
{
self.resetText.toggle()
}
}
})
{
Text("Animate")
.font(.headline)
.frame(width:125, height: 30)
.padding()
}
}
}
}
Also, I did try taking out the withAnimation
function call inside the Button's action as shown here, but that did not fix it.
if (!self.isAnimationOn) {
self.showMessageText.toggle()
}