This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 54).
DateTimePicker
A Jetpack Compose DateTimePicker component for selecting dates and times.
Expo UI DateTimePicker matches the official Jetpack Compose Date Picker and Time Picker APIs and supports date, time, and combined selection.
Installation
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
Usage
Date picker
import { useState } from 'react'; import { Host, DateTimePicker } from '@expo/ui/jetpack-compose'; export default function DatePickerExample() { const [selectedDate, setSelectedDate] = useState(new Date()); return ( <Host matchContents> <DateTimePicker onDateSelected={date => { setSelectedDate(date); }} displayedComponents="date" initialDate={selectedDate.toISOString()} variant="picker" /> </Host> ); }
Time picker
import { useState } from 'react'; import { Host, DateTimePicker } from '@expo/ui/jetpack-compose'; export default function TimePickerExample() { const [selectedDate, setSelectedDate] = useState(new Date()); return ( <Host matchContents> <DateTimePicker onDateSelected={date => { setSelectedDate(date); }} displayedComponents="hourAndMinute" initialDate={selectedDate.toISOString()} variant="picker" /> </Host> ); }
Input variant
Use variant="input" to display the picker as a text input field instead of the default picker UI.
import { useState } from 'react'; import { Host, DateTimePicker } from '@expo/ui/jetpack-compose'; export default function InputVariantExample() { const [selectedDate, setSelectedDate] = useState(new Date()); return ( <Host matchContents> <DateTimePicker onDateSelected={date => { setSelectedDate(date); }} displayedComponents="date" initialDate={selectedDate.toISOString()} variant="input" /> </Host> ); }
API
import { DateTimePicker } from '@expo/ui/jetpack-compose';
Component
Type: React.Element<DateTimePickerProps>
Renders a DateTimePicker component.
DisplayedComponents • Default: 'date'The components that the picker should display.
On Android, you can have a picker that selects just the date or just the time.
dateAndTime is only available on iOS and will result in a date picker on Android.
On iOS, you can have a picker that selects both date and time.
unionThe initial date to display on the picker.
Acceptable values are: string | null
boolean • Default: trueDetermines what format the clock should be displayed in on Android.
(date: Date) => voidCallback function that is called when a date is selected.
boolean • Default: trueShow to button to toggle between variants on Android.
AndroidVariant • Default: 'picker'The variant of the picker, which determines its appearance and behavior.