lorenzo
lorenzo

Reputation: 1743

SwiftUI DatePicker triggers touch events when dismissed

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!

Upvotes: 2

Views: 785

Answers (2)

palme
palme

Reputation: 2619

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.

Upvotes: 2

Maximilian
Maximilian

Reputation: 1

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

Upvotes: 0

Related Questions