2

When I develop the feature that allows users drag ScrollView to dismiss keyboard in SwiftUI, I find that if you drag ScrollView as the keyboard is dismissing, the ScrollView will flicker. That will destroy the experience of the feature.

Here's the video and minimal code example:

Video

struct ContentView: View {
  
  @State var text:String = ""
  
  var body: some View {
    ScrollView {
      Rectangle()
        .frame(height: 300)
      TextField("test", text: $text)
        .padding()
        .background(Color.gray)
        .padding()
    }
  }
}
  • your code works fine with me, no flicker when dismissing the keyboard. Is some code missing? – ChrisR Feb 11 '22 at 16:11
  • I suspect there is as the OP describes a feature that dismiss keyboard on a drag not he scrollview. There is nothing of the sort here in code. – Yrb Feb 11 '22 at 16:20
  • @ChrisR You should drag the ScrollView manually as the keyboard is dismissing. I didn't add the drag-to-dismiss code in the example. – Chang Tanshow Feb 11 '22 at 18:38

1 Answers1

1

It's caused because the keyboard forces the view to resize. Add

.ignoresSafeArea(.keyboard, edges: .bottom) to the bottom of your view to solve this issue

Roma Kavinskyi
  • 268
  • 4
  • 12