Freeze animation when keyboard appears SwiftUI

93 Views Asked by At

We have Rectangle and TextField on screen. When view appears we animate Rectangle offset. When tap on TextField and keyboard appears at this moment the animation starts little freeze. How to prevent this freeze behaviour ?

This issue happens on simulator and device. Xcode 15.1, Swift version 5.9.2. iOS 17.2.

Here is simple code snippet to reproduce my issue.

import SwiftUI

struct ContentView: View {
    @State private var offset: CGFloat = 0
    @State private var input = ""
    
    var body: some View {
        VStack(alignment: .leading) {
            Rectangle()
                .fill(Color.red)
                .frame(width: 100, height: 100)
                .offset(x: offset)
                .padding()
            Spacer()
            TextField("Title", text: $input)
            Spacer()
        }
        .animation(.easeIn(duration: 5).repeatForever(autoreverses: true), value: offset)
        .onAppear(perform: {
            offset = 200
        })
    }
}

Someone knows how to fix this issue?

0

There are 0 best solutions below