Gathering detailed insights and metrics for react-native-modal-datetime-picker
Gathering detailed insights and metrics for react-native-modal-datetime-picker
Gathering detailed insights and metrics for react-native-modal-datetime-picker
Gathering detailed insights and metrics for react-native-modal-datetime-picker
A React-Native datetime-picker for Android and iOS
npm install react-native-modal-datetime-picker
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2,981 Stars
468 Commits
400 Forks
34 Watching
2 Branches
93 Contributors
Updated on 27 Nov 2024
JavaScript (64.49%)
Java (16.57%)
Objective-C (11.81%)
Starlark (5.1%)
Ruby (2.03%)
Cumulative downloads
Total Downloads
Last day
-6.6%
70,207
Compared to previous day
Last week
3.4%
359,218
Compared to previous week
Last month
10.7%
1,502,285
Compared to previous month
Last year
37.2%
14,806,624
Compared to previous year
A declarative cross-platform react-native date and time picker.
This library exposes a cross-platform interface for showing the native date-picker and time-picker inside a modal, providing a unified user and developer experience.
Under the hood, this library is using @react-native-community/datetimepicker
.
If your project is not using Expo, install the library and the community date/time picker using npm or yarn:
1# using npm 2$ npm i react-native-modal-datetime-picker @react-native-community/datetimepicker 3 4# using yarn 5$ yarn add react-native-modal-datetime-picker @react-native-community/datetimepicker
Please notice that the @react-native-community/datetimepicker
package is a native module so it might require manual linking.
If your project is using Expo, install the library and the community date/time picker using the Expo CLI:
1npx expo install react-native-modal-datetime-picker @react-native-community/datetimepicker
To ensure the picker theme respects the device theme, you should also configure the appearance styles in your app.json
this way:
1{ 2 "expo": { 3 "userInterfaceStyle": "automatic" 4 } 5}
Refer to the Appearance documentation on Expo for more info.
1import React, { useState } from "react"; 2import { Button, View } from "react-native"; 3import DateTimePickerModal from "react-native-modal-datetime-picker"; 4 5const Example = () => { 6 const [isDatePickerVisible, setDatePickerVisibility] = useState(false); 7 8 const showDatePicker = () => { 9 setDatePickerVisibility(true); 10 }; 11 12 const hideDatePicker = () => { 13 setDatePickerVisibility(false); 14 }; 15 16 const handleConfirm = (date) => { 17 console.warn("A date has been picked: ", date); 18 hideDatePicker(); 19 }; 20 21 return ( 22 <View> 23 <Button title="Show Date Picker" onPress={showDatePicker} /> 24 <DateTimePickerModal 25 isVisible={isDatePickerVisible} 26 mode="date" 27 onConfirm={handleConfirm} 28 onCancel={hideDatePicker} 29 /> 30 </View> 31 ); 32}; 33 34export default Example;
👉 Please notice that all the @react-native-community/react-native-datetimepicker
props are supported as well!
Name | Type | Default | Description |
---|---|---|---|
buttonTextColorIOS | string | The color of the confirm button texts (iOS) | |
backdropStyleIOS | style | The style of the picker backdrop view style (iOS) | |
cancelButtonTestID | string | Used to locate cancel button in end-to-end tests | |
cancelTextIOS | string | "Cancel" | The label of the cancel button (iOS) |
confirmButtonTestID | string | Used to locate confirm button in end-to-end tests | |
confirmTextIOS | string | "Confirm" | The label of the confirm button (iOS) |
customCancelButtonIOS | component | Overrides the default cancel button component (iOS) | |
customConfirmButtonIOS | component | Overrides the default confirm button component (iOS) | |
customHeaderIOS | component | Overrides the default header component (iOS) | |
customPickerIOS | component | Overrides the default native picker component (iOS) | |
date | obj | new Date() | Initial selected date/time |
isVisible | bool | false | Show the datetime picker? |
isDarkModeEnabled | bool? | undefined | Forces the picker dark/light mode if set (otherwise fallbacks to the Appearance color scheme) (iOS) |
modalPropsIOS | object | {} | Additional modal props for iOS |
modalStyleIOS | style | Style of the modal content (iOS) | |
mode | string | "date" | Choose between "date", "time", and "datetime" |
onCancel | func | REQUIRED | Function called on dismiss |
onChange | func | () => null | Function called when the date changes (with the new date as parameter). |
onConfirm | func | REQUIRED | Function called on date or time picked. It returns the date or time as a JavaScript Date object |
onHide | func | () => null | Called after the hide animation |
pickerContainerStyleIOS | style | The style of the picker container (iOS) | |
pickerStyleIOS | style | The style of the picker component wrapper (iOS) | |
pickerComponentStyleIOS | style | The style applied to the actual picker component - this can be either a native iOS picker or a custom one if customPickerIOS was provided |
This repo is only maintained by me, and unfortunately I don't have enough time for dedicated support & question.
If you're experiencing issues, please check the FAQs below.
For questions and support, please start try starting a discussion or try asking it on StackOverflow.
⚠️ Please use the GitHub issues only for well-described and reproducible bugs. Question/support issues will be closed.
Under the hood react-native-modal-datetime-picker
uses @react-native-community/datetimepicker
.
If you're experiencing issues, try swapping react-native-datetime-picker
with @react-native-community/datetimepicker
. If the issue persists, check if it has already been reported as a an issue or check the other FAQs.
Set the mode
prop to time
.
You can also display both the datepicker and the timepicker in one step by setting the mode
prop to datetime
.
Please make sure you're using the date
props (and not the value
one).
Yes!
You can set the display
prop (that we'll pass down to react-native-datetimepicker
) to inline
to use the new iOS 14 picker.
Please notice that you should probably avoid using this new style with a time-only picker (so with
mode
set totime
) because it doesn't suit well this use case.
This seems to be a known issue of the @react-native-community/datetimepicker
. Please see this thread for a couple of workarounds. The solution, as described in this reply is hiding the modal, before doing anything else.
The most common approach for solving this issue when using an Input
is:
Input
with a "Pressable
"/Button
(TouchableWithoutFeedback
/TouchableOpacity
+ activeOpacity={1}
for example)Input
from being focused. You could set editable={false}
too for preventing Keyboard openinghideModal()
callback as a first thing inside onConfirm
/onCancel
callback props1const [isVisible, setVisible] = useState(false); 2const [date, setDate] = useState(''); 3 4<TouchableOpacity 5 activeOpacity={1} 6 onPress={() => setVisible(true)}> 7 <Input 8 value={value} 9 editable={false} // optional 10 /> 11</TouchableOpacity> 12<DatePicker 13 isVisible={isVisible} 14 onConfirm={(date) => { 15 setVisible(false); // <- first thing 16 setValue(parseDate(date)); 17 }} 18 onCancel={() => setVisible(false)} 19/>
You can't — @react-native-community/datetimepicker
doesn't allow you to do so. That said, you can allow only "range" of dates by setting a minimum and maximum date. See below for more info.
You can use the minimumDate
and maximumDate
props from @react-native-community/datetimepicker
.
This is more a React-Native specific question than a react-native-modal-datetime-picker one.
See issue #29 and #106 for some solutions.
The is24Hour
prop is only available on Android but you can use a small hack for enabling it on iOS by setting the picker timezone to en_GB
:
1<DatePicker 2 mode="time" 3 locale="en_GB" // Use "en_GB" here 4 date={new Date()} 5/>
Under the hood this library is using @react-native-community/datetimepicker
. You can't change the language/locale from react-native-modal-datetime-picker
. Locale/language is set at the native level, on the device itself.
On iOS, you can set an automatic detection of the locale (fr_FR
, en_GB
, ...) depending on the user's device locale.
To do so, edit your AppDelegate.m
file and add the following to didFinishLaunchingWithOptions
.
1// Force DatePicker locale to current language (for: 24h or 12h format, full day names etc...) 2NSString *currentLanguage = [[NSLocale preferredLanguages] firstObject]; 3[[UIDatePicker appearance] setLocale:[[NSLocale alloc]initWithLocaleIdentifier:currentLanguage]];
Please make sure you're on the latest version of react-native-modal-datetime-picker
and of the @react-native-community/datetimepicker
.
We already closed several iOS 14 issues that were all caused by outdated/cached versions of the community datetimepicker.
Please make sure you're on the latest version of react-native-modal-datetime-picker
and of @react-native-community/datetimepicker
.
Also, double-check that the picker light/dark theme is aligned with the OS one (e.g., don't "force" a theme using isDarkModeEnabled
).
Unfortunately this is a know issue with React-Native on iOS. Even by using the onHide
callback exposed by react-native-modal-datetime-picker
you might not be able to show the (native) alert successfully. The only workaround that seems to work consistently for now is to wrap showing the alter in a setTimeout 😔:
1const handleHide = () => { 2 setTimeout(() => Alert.alert("Hello"), 0); 3};
See issue #512 for more info.
onConfirm
not match the picked date (on iOS)?On iOS, clicking the "Confirm" button while the spinner is still in motion — even just slightly in motion — will cause the onConfirm
callback to return the initial date instead of the picked one. This is is a long standing iOS issue (that can happen even on native app like the iOS calendar) and there's no failproof way to fix it on the JavaScript side.
See this GitHub gist for an example of how it might be solved at the native level — but keep in mind it won't work on this component until it has been merged into the official React-Native repo.
Related issue in the React-Native repo here.
See issue #216 for a possible workaround.
Please see the contributing guide.
The library is released under the MIT license. For more details see LICENSE
.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
binaries present in source code
Details
Reason
Found 13/30 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
74 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More