React Native date & time picker component for iOS, Android and Windows
React Native date & time picker component for iOS, Android and Windows
Please support maintenance of the module with a monthly donation or help us with issues and pull requests.
Become a backer on OpenCollective or sponsor us on GitHub Sponsors.
See this issue for context. Thank you!
This repository was moved out of the react native community GH organization, in accordance to this proposal.
The module is still published on npm under the old namespace (as documented) but will be published under a new namespace at some point, with a major version bump.
[![npm downloads][npm-downloads-badge]][npm-downloads-link] ![Supports Android and iOS][support-badge] ![MIT License][license-badge]
React Native date & time picker component for iOS, Android and Windows (please note Windows is not actively maintained).
| iOS | |
| Android | |
| Windows | |
mode (optional)display (optional)design (optional, Android only)initialInputMode (optional, Android only)title (optional, Android only)fullscreen (optional, Android only)startOnYearSelection (optional, Android only)onValueChange (optional)onDismiss (optional)onNeutralButtonPress (optional, Android only)onChange (optional, deprecated)value (required)maximumDate (optional)minimumDate (optional)timeZoneName (optional, iOS or Android only)timeZoneOffsetInMinutes (optional, iOS or Android only)timeZoneOffsetInSeconds (optional, Windows only)dayOfWeekFormat (optional, Windows only)dateFormat (optional, Windows only)firstDayOfWeek (optional, Android and Windows only)textColor (optional, iOS only)accentColor (optional, iOS only)themeVariant (optional, iOS only)locale (optional, iOS only)is24Hour (optional, Windows and Android only)positiveButton (optional, Android only)negativeButton (optional, Android only)neutralButton (optional, Android only)minuteInterval (optional)style (optional, iOS only)disabled (optional, iOS only)view props (optional, iOS only)onError (optional, Android only)The module supports the new React Native architecture (Fabric rendering of iOS components, and turbomodules on Android).
This module is part of Expo Go - see docs. However, Expo Go may not contain the latest version of the module and therefore, the newest features and bugfixes may not be available.
If you use Expo Go, use the command npx expo install @react-native-community/datetimepicker (not yarn or npm) to install this module - Expo will automatically install the latest version compatible with your Expo SDK (which may not be the latest version of the module available).
If you're using a Dev Client, rebuild the Dev Client after installing the dependencies.
If you're using the expo prebuild command and building your native app projects (e.g. with EAS Build or locally), you can use the latest version of the module.
npm install @react-native-community/datetimepicker --saveor
yarn add @react-native-community/datetimepickerAutolinking is not yet implemented on Windows, so manual installation is needed.
On iOS, run npx pod-install after installing. Then rebuild your project.
import DateTimePicker from '@react-native-community/datetimepicker';We give two equivalent examples on how to use the package on all supported platforms.
While the component-approach as given in the second paragraph works on Android, the recommended approach is to use the imperative api given in the first paragraph.
Read more about the motivation in Android imperative API.
……By localization, we refer to the language (names of months and days), as well as order in which date can be presented in a picker (month/day vs. day/month) and 12 / 24 hour-format.
On Android, the picker will be controlled by the system locale. If you wish to change it, see instructions here.
On iOS, use XCode, as documented here to inform the OS about the locales your application supports. iOS will automatically display the correctly localized DateTimePicker as long as the target language is contained in project.pbxproj.
If you use a library like i18next or react-localize-redux to manage your translations, it is sufficient to add your target languages as described in the Apple Documentation - but you are not required to add any localization keys (like, for example, the days of the week). iOS will automatically display the correct localized strings as long as the target language is contained in
project.pbxproj.
For testing your localization setup, refer here.
There is also the iOS-only locale prop that can be used to force locale in some cases but its usage is discouraged due to not working robustly in all picker modes (note the mixed month and day names). To the best of our knowledge, it works reliably in the spinner mode.
For Expo, follow the localization docs.
On Android, you have a choice between using the component API (regular React component) or an imperative api (think of something like ReactNative.alert()).
While the component API has the benefit of writing the same code on all platforms, for start we recommend using the imperative API on Android.
The params is an object with the same properties as the component props documented in the next paragraph. (This is also because the component api internally uses the imperative one.)
import { DateTimePickerAndroid } from '@react-native-community/datetimepicker';
DateTimePickerAndroid.open(params: AndroidNativeProps)
DateTimePickerAndroid.dismiss(mode: AndroidNativeProps['mode'], design?: AndroidNativeProps['design'])The reason we recommend the imperative API is: on Android, the date/time picker opens in a dialog, similar to ReactNative.alert() from core react native. The imperative api models this behavior better than the declarative component api. While the component approach is perfectly functional, based on the issue tracker history, it appears to be more prone to introducing bugs.
If you'd like to use the Material pickers, your app theme will need to inherit from Theme.Material3.DayNight.NoActionBar in styles.xml.
Styling of the dialogs on Android can be easily customized by using the provided config plugin, provided that you use a Expo development build. The plugin allows you to configure color properties that cannot be set at runtime and requires building a new app binary to take effect.
Refer to this documentation for more information: android-styling.md.
Please note that this library currently exposes functionality from
UIDatePickeron iOS and DatePickerDialog + TimePickerDialog on Android, andCalendarDatePicker+ TimePicker on Windows.These native classes offer only limited configuration, while there are dozens of possible options you as a developer may need. It follows that if your requirement is not supported by the backing native views, this library will not be able to implement your requirement. When you open an issue with a feature request, please document if (or how) the feature can be implemented using the aforementioned native views. If the native views do
No open issues yet, or sync has not completed.