1

I have a weird issue when I embed a TextField in a modal (sheet). I wrote a basic sample code to showcase the issue:

struct ContentView: View {
  @State var showSheet = false
  @State var text = ""

  var body: some View {
    Button("Show Text Field", action: {
      showSheet = true
    })
    .sheet(isPresented: $showSheet, content: {
      TextField("Type here...", text: $text)
        .textFieldStyle(RoundedBorderTextFieldStyle())
        .disableAutocorrection(true)
        .frame(width: 300, height: 60, alignment: .center)
    })
  }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

With this simple basic code, iPad OS generates a bunch of Layer Constraints conflicts when the TextField becomes first responder:

Xcode Console

Any idea how to fix that? Super thanks.

MohG
  • 351
  • 4
  • 11

0 Answers0