Home > Mobile >  SwiftUI DatePicker triggers touch events when dismissed
SwiftUI DatePicker triggers touch events when dismissed

Time:10-16

I have a compact DatePicker that displays a calendar when opened with a rather standard declaration:

    DatePicker(
        self.name,
        selection: self.$date,
        displayedComponents: self.components
    ).labelsHidden()

After selecting a date, I want to tap outside the calendar to dismiss and validate my date. The problem is the tap triggers touch events whereever I tapped. How to have the DatePicker calendar behaving as a real modal popover?

Thanks!

CodePudding user response:

You could use a gesture recognizer on the Datepicker to bind the touch action to the picker

CodePudding user response:

We had the similar idea and could only solve it by (and you probably thought of that already) putting an invisible view behind it and register the tap gesture.

  • Related