ios – The way to stop bizarre animation with footer button and keyboard in SwiftUI

0
85


I’ve this bizarre SwiftUI keyboard animation bug that’s at the moment reside in certainly one of my apps and I’m struggling to repair it and would respect any assist in understanding the underlying downside and learn how to clear up it.

Under is instance code made up of easy view that comprises a TextField and a Footer Button. I set the TextField to get focus after 0.75 seconds when the view seems.

Sadly, the beneath code leads to an animation bug the place the background behind the footer button flashes briefly because the keyboard finishes animating on to the display screen.

struct NameTextFieldView: View {
    @Surroundings(.dismiss) var dismiss
    @FocusState non-public var isFocused: Bool
    @State non-public var identify: String = ""
    
    var physique: some View {
        NavigationStack {
            Kind {
                TextField("Identify", textual content: $identify)
                    .targeted($isFocused)
                    .onAppear {
                        DispatchQueue.major.asyncAfter(deadline: .now() + 0.75) {
                          isFocused = true
                        }
                    }
            }
            .safeAreaInset(edge: .backside) {
                Button(motion: {
                    dismiss()
                }, label: {
                    Textual content("Add")
                        .foregroundStyle(Coloration.white)
                })
                .body(width: 200, top: 44)
                .background(Coloration.blue)
                .clipShape(RoundedRectangle(cornerSize: CGSize(width: 20, top: 10)))
                .padding()
                
            }
            .navigationTitle("Add Identify")
            .navigationBarTitleDisplayMode(.inline)
        }
        
    }
} 

Odd animation bug.

animation bug