Skip to content

Commit cd08b3e

Browse files
committed
Fix DatePickerComponents exclusion on unsupported platforms
1 parent 5771a45 commit cd08b3e

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

Sources/LiveViewNative/Views/Controls and Indicators/Pickers/DatePicker.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,30 @@ struct DatePicker<Root: RootRegistry>: View {
4848
///- `hourAndMinute`
4949
///- `date`
5050
@_documentation(visibility: public)
51-
private var components: DatePickerComponents = [.hourAndMinute, .date]
51+
private var components: String?
52+
53+
#if os(iOS) || os(macOS)
54+
private var datePickerComponents: DatePickerComponents {
55+
components.flatMap({ DatePickerComponents.init(from: $0) }) ?? [.hourAndMinute, .date]
56+
}
57+
#endif
5258

5359
var body: some View {
5460
#if os(iOS) || os(macOS)
5561
if let start, let end {
56-
SwiftUI.DatePicker(selection: $selection.date, in: start...end, displayedComponents: components) {
62+
SwiftUI.DatePicker(selection: $selection.date, in: start...end, displayedComponents: datePickerComponents) {
5763
$liveElement.children()
5864
}
5965
} else if let start {
60-
SwiftUI.DatePicker(selection: $selection.date, in: start..., displayedComponents: components) {
66+
SwiftUI.DatePicker(selection: $selection.date, in: start..., displayedComponents: datePickerComponents) {
6167
$liveElement.children()
6268
}
6369
} else if let end {
64-
SwiftUI.DatePicker(selection: $selection.date, in: ...end, displayedComponents: components) {
70+
SwiftUI.DatePicker(selection: $selection.date, in: ...end, displayedComponents: datePickerComponents) {
6571
$liveElement.children()
6672
}
6773
} else {
68-
SwiftUI.DatePicker(selection: $selection.date, displayedComponents: components) {
74+
SwiftUI.DatePicker(selection: $selection.date, displayedComponents: datePickerComponents) {
6975
$liveElement.children()
7076
}
7177
}
@@ -103,10 +109,10 @@ private struct CodableDate: FormValue, AttributeDecodable {
103109
#if !os(iOS) && !os(macOS)
104110
typealias DatePickerComponents = Never
105111
#else
106-
extension DatePickerComponents: AttributeDecodable {
107-
public init(from attribute: LiveViewNativeCore.Attribute?, on element: ElementNode) throws {
112+
extension DatePickerComponents {
113+
public init(from string: String) {
108114
#if os(iOS) || os(macOS)
109-
switch attribute?.value {
115+
switch string {
110116
case "hourAndMinute":
111117
self = .hourAndMinute
112118
case "date":

0 commit comments

Comments
 (0)