Currently there is no native SwiftUIDatePicker for tvOS. That’s why I created this Swift package to fill the hole 😊
The API mimics the one of the native SwiftUIDatePicker available for iOS, macOS and macCatalyst.
ℹ️ Installation
Just add this Swift package as a dependency to your Package.swift:
At first the view appears as a button with a horizontal stack containing the specified label, a Text view representing the current selection date string and a disclosure indicatorImage view. If you press the button a sheet with the actual date picker view appears. The following screenshot is an example:
📖 Implementation
The DatePicker view is implemented by using multiple Pickers with the SegmentedPickerStyle inside a List / VStack.
Each Picker represents a date component like year, month or date. Due to issues with the focus engine the implementation slightly differs for the supported tvOS versions 13.0, 14.0 and > 14.0. But I think that you can ignore this detail in most cases.
🔒 Limitations
⚠️ The DatePicker was only tested with the Gregorian calendar.
The year component displays only 10 years at a time (selected year +/- 5 years with respect to the year of the specified minimum date).
⚠️ Currently only the year component respects the minimum date. On the contrary all months of a year and all days of a month are visible at all time.
Currently the hourAndMinute component always displays all 24 hours of a day.
The hourAndMinute component supports only steps by five for the minute.
📅 TVDatePicker
A
SwiftUIDatePickerview fortvOS❤️ Motivation
Currently there is no native
SwiftUIDatePickerfortvOS. That’s why I created this Swift package to fill the hole 😊 TheAPImimics the one of the nativeSwiftUIDatePickeravailable foriOS,macOSandmacCatalyst.ℹ️ Installation
Just add this Swift package as a dependency to your
Package.swift:🧭 Usage
The following code snippet shows how to use the
DatePickerviewin yourtvOSapplication:At first the view appears as a button with a horizontal stack containing the specified
label, aTextview representing the currentselectiondate string and adisclosure indicatorImageview. If you press the button a sheet with the actual date picker view appears. The following screenshot is an example:📖 Implementation
The
DatePickerview is implemented by using multiplePickers with theSegmentedPickerStyleinside aList/VStack. EachPickerrepresents a date component likeyear,monthordate. Due to issues with the focus engine the implementation slightly differs for the supported tvOS versions13.0,14.0and >14.0. But I think that you can ignore this detail in most cases.🔒 Limitations
DatePickerwas only tested with theGregorian calendar.yearcomponent displays only10years at a time (selected year +/- 5 yearswith respect to the year of the specifiedminimum date).yearcomponent respects theminimum date. On the contraryall months of a yearandall days of a monthare visible at all time.hourAndMinutecomponent always displays all24 hoursof a day.hourAndMinutecomponent supports only steps by five for theminute.