Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-native-datepicker

xgfe39.5kMIT1.7.2TypeScript support: definitely-typed

React Native DatePicker component for both Android and iOS, useing DatePickerAndroid, TimePickerAndroid and DatePickerIOS

react-native, DatePicker

readme

react-native-datepicker Build Status Coverage Status Monthly download Total downloads

React Native DatePicker component for both Android and iOS, using DatePickerAndroid, TimePickerAndroid and DatePickerIOS

Install

npm install react-native-datepicker --save

Or using react-native-ui-xg, our react-naitve ui kit.

npm install react-native-ui-xg --save

Example

Check index.android.js in the Example.

android ios

Usage


import React, { Component } from 'react'
import DatePicker from 'react-native-datepicker'

export default class MyDatePicker extends Component {
  constructor(props){
    super(props)
    this.state = {date:"2016-05-15"}
  }

  render(){
    return (
      <DatePicker
        style={{width: 200}}
        date={this.state.date}
        mode="date"
        placeholder="select date"
        format="YYYY-MM-DD"
        minDate="2016-05-01"
        maxDate="2016-06-01"
        confirmBtnText="Confirm"
        cancelBtnText="Cancel"
        customStyles={{
          dateIcon: {
            position: 'absolute',
            left: 0,
            top: 4,
            marginLeft: 0
          },
          dateInput: {
            marginLeft: 36
          }
          // ... You can check the source to find the other keys.
        }}
        onDateChange={(date) => {this.setState({date: date})}}
      />
    )
  }
}

You can check index.js in the Example for detail.

Properties

Prop Default Type Description
style - object Specify the style of the DatePicker, eg. width, height...
date - string | date | Moment instance Specify the display date of DatePicker. string type value must match the specified format
mode 'date' enum The enum of date, datetime and time
androidMode 'default' enum The enum of default, calendar and spinner (only Android)
format 'YYYY-MM-DD' string Specify the display format of the date, which using moment.js. The default value change according to the mode.
confirmBtnText '确定' string Specify the text of confirm btn in ios.
cancelBtnText '取消' string Specify the text of cancel btn in ios.
iconSource - {uri: string} | number Specify the icon. Same as the source of Image, always using require()
minDate - string | date Restricts the range of possible date values.
maxDate - string | date Restricts the range of possible date values.
duration 300 number Specify the animation duration of datepicker.
customStyles - object The hook of customize datepicker style, same as the native style. dateTouchBody, dateInput...
showIcon true boolean Controller whether or not show the icon
hideText false boolean Controller whether or not show the dateText
iconComponent - element Set the custom icon
disabled false boolean Controller whether or not disable the picker
is24Hour - boolean Set the TimePicker is24Hour flag. The default value depend on format. Only work in Android
allowFontScaling true boolean Set to false to disable font scaling for every text component
placeholder '' string The placeholder show when this.props.date is falsy
onDateChange - function This is called when the user confirm the picked date or time in the UI. The first and only argument is a date or time string representing the new date and time formatted by moment.js with the given format property.
onOpenModal - function This is called when the DatePicker Modal open.
onCloseModal - function This is called when the DatePicker Modal close
onPressMask - function This is called when clicking the ios modal mask
modalOnResponderTerminationRequest - function Set the callback for React Native's Gesture Responder System's call to onResponderTerminationRequest. By default this will reject a termination request, but can be overidden in case the View under the Modal is implementing custom gesture responders, and you wish for those to be overidden in certain cases.
TouchableComponent TouchableHighlight Component Replace the TouchableHighlight with a custom Component. For example : TouchableOpacity
getDateStr - Function A function to override how to format the date into a String for display, receives a Date instance

Property customStyles available keys

  • appearance: dateInput, disabled, dateTouchBody, dateIcon, placeholderText, dateText
  • ios select panel: datePickerCon, datePicker, btnConfirm, btnTextConfirm, btnCancel, btnTextCancel

Instance Methods

Method Params Description
onPressDate - Manually open the date picker panel
onPressCancel - Manually close the date picker panel like, similarly pressing cancel btn

changelog

1.7.2 (2018-04-22)

Bug Fixes

  • datepicker: fix androidMode enum not support 'clock' bug (dc29a09)

1.7.0 (2018-04-08)

Bug Fixes

  • datepicker: fix warns when pass moment instance to date prop (7450bba), closes #166

Features

  • datepicker: add getDateStr prop to customize display outside moment format (905dfbd)
  • datepicker: pass locale to native control if given (60e3887)
  • datepicker: merge some PR for bugs (5377499)

1.6.0 (2017-06-12)

Features

  • datepicker: adding testIds to elements (#138
  • datepicker: add hideText property to hide the Date Text (#127
  • datepicker: add TouchableComponent property to support custom touchable components (#128

1.5.1 (2017-05-16)

Features

  • datepicker: change datepicker switch gap timeout to 200ms (5b6e78f)

Bug Fixes

1.5.0 (2017-05-15)

Features

  • datepicker: Add onPressMask prop for ios (#120, 09ecdf8)
  • datepicker: Ability to pass icon component with iconComponent property (#124, 35150ed)

Bug Fixes

  • datepicker: Fix onCloseModal for android (#122, ba55c06)

1.4.7 (2017-04-13)

Bug Fixes

  • datepicker: fix androidMode prop pass bug (#111, 095f756)

1.4.6 (2017-04-05)

Features

  • datepicker: add androidMode property for DatePickerAndroid & TimePickerAndroid (be30731)

1.4.5 (2017-03-21)

Bug Fixes

  • datepicker: fix date prop change not invoke state change bug (#93, 3c8099b)

1.4.4 (2017-02-06)

Features

  • datepicker: Added two new properties: onOpenModal and onCloseModal (#77, 846ae35)
  • Datepicker: Add animation on datepicker dismiss (#76, fdfcc21)

Bug Fixes

  • datepicker: fix datepicker can't open in landscape mode bug (#28, 3a9df99)

1.4.3 (2016-12-13)

Bug Fixes

  • datepicker: fix disabled props change not update bug #66 (7579dc9), closes #66
  • datepicker: fix is24Hour flag can't be specified bug (c320e56), closes #69

Reverts

  • datepicker: revert responder prevert func temporary #47 #50 (5b9f60c)

1.4.1 (2016-11-03)

Bug Fixes

  • datepicker: fix btn not work in 7p bug #50 (8285d2d), closes #50

1.4.0 (2016-10-31)

Features

  • datepicker: default prevent manual panResonder when mdal shown (6d1c1d0)
  • Datepicker: support minuteInterval property in ios #46 (3ae69a4)

1.3.2 (2016-08-02)

Bug Fixes

  • datepicker: fix default date bug without selecting (b08fb7e)

1.3.1 (2016-07-25)

Features

  • datepicker: add placeholder when this.props.date is falsy(1430f06)

Refactor

  • datepicker: refactor datepicker with official ES6 Classes pattern(fb5f6e2)

1.3.0 (2016-07-11)

Bug Fixes

  • datepicker: fix the DatepickerIOS align bug above 0.28.0 with the removing of width (b51b9ca)
  • readme: fix readme gif img #17 (49e310e), closes #17

Breaking Change

  • can't be center automatic below 0.28.0(b51b9ca).

1.2.2 (2016-06-22)

Features

  • datepicker: add supoort of showIcon property (f274179)

1.2.1 (2016-05-19)

Bug Fixes

  • datepicker: fix datepicker Modal adaptation with different width on ios(b3234bd)

1.2.0 (2016-05-17)

Breaking Change

  • Upgrade Requiring React API, Requiring from react-native is now deprecated. Work after 0.24.(53b0846)

1.1.0 (2016-05-06)

Features

  • datepicker: add support for custom btn text(1bbd66e)
  • datepicker: add support for custom icon(7ffbe43)
  • datepicker: add support for custom styles with customStyles property(cb254e4)

1.0.3 (2016-04-27)

Features

  • datepicker: optimize the animation of datepicker, and add support for duration property(91fa55c)

1.0.2 (2016-04-26)

1.0.1 (2016-04-26)

1.0.0 (2016-04-25)