SwiftUI ScrollView extra padding when go to another screen with showed keyboard

240 views Asked by At

The default "Keyboard Avoidance" SwiftUI is used. First GIF

If you put the code in VStack and add another View to it, then the container rises Second GIF

I don't want to delete Keyboard Avoidance. I need to remove extra spacing

scrollDismissesKeyboard for ScrollView is not an option

minimal iOS version is iOS 16

struct ContentView: View {
    @State var text: String = "Bu bu?"
    var body: some View {
        NavigationStack {
            ScrollViewReader { proxy in
                VStack {
                    ScrollView(showsIndicators: false) {
                        VStack(spacing: 0) {
                            Spacer()
                                .frame(height: 500)
                            TextField("", text: $text)
                                .padding(.bottom, 70)
                                .frame(height: 40)
                                .frame(maxWidth: .infinity)
                                .background(Color.red)
                            NavigationLink("Screen 2", destination: {
                                Text("SwiftUI - Nice to meet you, let's never meet again")
                            })
                        }
                    }
                    Text("I'm in VSTack after scroll view")
                }
            }
        }
    }
}

I looked it up with a hierarchy view, and noticed that a UIInputSetHostView is created with a height of 216 View hierarchy 1 View hierarchy 2

disableAutocorrection not working

0

There are 0 answers