SwiftUI TextField does not work after adding gesture

Viewed 519

After adding a combined gesture to a view, a TextField inside the view would no longer respond when I would tap into it to change the text. I discovered this after adding a custom combined gesture - where I used a long press to start things before dragging. (Note: things still worked if just a drag gesture was added. Not sure what is particularly different between these two cases.)

The combined gesture:

let combined = longPressGesture.simultaneously(with: dragGesture)

The gesture was added to the view with:

.gesture(combined)
2 Answers

I got things to work by adding an onTapGesture{} to the TextField. Didn’t have to put anything into the action. Seems like a side effect whose behavior could change in the future. Appreciate any comments on if this makes sense or other ways to handle.

TextField(“Enter Text”, text: $myText)
                        .textFieldStyle(RoundedBorderTextFieldStyle())
                        .onTapGesture {}
Related