0
votes

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

2 Answers

1
votes

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 {}
0
votes

In case one would have this issue with a drag gesture, you can set the minimumDistance. This would still register the tap on the textfield to edit it.

DragGesture(minimumDistance: 30, coordinateSpace: .global)

Adding a drag gesture in SwiftUI to a View inside a ScrollView blocks the scrolling