'SwiftUI dragging ScrollView flickers as the keyboard is dismissing

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()
    }
  }
}


Solution 1:[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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Roma Kavinskyi