DatePickerComponents2

The date and time components that a date picker shows.

StructureiOS 13.0+macOS 10.15+watchOS 10.0+DatePickerComponents in SwiftUI

Declaration

React
type DatePickerComponents2 =
  | ('date'
  | 'hourAndMinute'
  | { rawValue: number; })
  | readonly ('date'
  | 'hourAndMinute'
  | { rawValue: number; })[];
Swift
struct DatePickerComponents

Pass a literal, or build one with SwiftUI.DatePickerComponents2 from import { SwiftUI } from 'swiftui-react-native'.

Overview

Pass a value of this type as the displayedComponents argument of a DatePicker initializer to choose which parts of a date someone can edit. Combine options to show more than one group.

DatePicker(
    "Departure",
    selection: $departure,
    displayedComponents: [.hourAndMinute, .date]
)

A picker shows [.hourAndMinute, .date] unless you choose otherwise. Each option respects the current locale, so DatePickerComponents.date orders the day, month, and year the way the person's region expects.

From Apple’s SwiftUI documentation. Code samples there are Swift.

See also

More in Other values.