How to Add LongPressGesture to SwiftUI DatePicker

129 Views Asked by At

simultaneousGesture(LongPressGesture()) breaks DatePicker default LongPressGesture and TapGesture.

My attempt:

DatePicker("title", selection: $selection, in: range, displayedComponents: .date)
  .simultaneousGesture(
    LongPressGesture()
      .onEnded { _ in
        doTheThing()
      }
  )
  .simultaneousGesture(
    TapGesture()
      .onEnded { _ in
        doTheThing()
      }
  )

I've removed the simultaneousGesture(TapGesture()) for testing and the results are the same.

What I'm experiencing: Adding the simultaneousGesture(LongPressGesture()) breaks the default long press and normal tap gestures (as well as the simultaneousGesture(TapGesture())). The added long press is called correctly, but the DatePicker does not open on tap or long press, which it should do by default. The function I am attempting to call needs to occur whenever the DatePicker is opened and I would otherwise not like to break the default behavior of the DatePicker.

0

There are 0 best solutions below