GithubHelp home page GithubHelp logo

xgfe / react-native-datepicker Goto Github PK

View Code? Open in Web Editor NEW
2.1K 2.1K 726.0 31.05 MB

react native datePicker component for both Android and IOS, useing DatePikcerAndroid, TimePickerAndroid and DatePickerIOS

License: MIT License

JavaScript 80.31% Python 4.51% Java 3.68% Objective-C 11.51%

react-native-datepicker's Introduction

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

react-native-datepicker's People

Contributors

aidenmontgomery avatar andrew-bednarz-isobar avatar atlanteh avatar avencat avatar believezjp avatar blackxored avatar brunocascio avatar brunolemos avatar ccarisleensemblegroup avatar chdwlch avatar chrissloey avatar costagolub avatar feyy avatar jdoyle65 avatar jemise111 avatar jrzimmerman avatar kashav avatar matuszeg avatar mrpohoda avatar pastinepolenta avatar s2t2 avatar tbergquist-godaddy avatar tomasreimers avatar ttpro1995 avatar weger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-datepicker's Issues

iOS "Invalid Date"

Hi

I came across the following issue for react-native-datepicker.

This is how I am using datepicker component:

<DatePicker
  mode='date'
  placeholder='DD-MM-YYYY'
  format='DD-MM-YYYY'
  date={this.state.dob}
  maxDate={moment()}
  showIcon={false}
  confirmBtnText='Confirm'
  cancelBtnText='Cancel'
  onDateChange={(dob) => { this.setState({dob}) }}
/>

Initially this.state.dob is an empty string "" so that placeholder is displayed to the user.

So when I click on datepicker component I have this:
screen shot 2016-07-28 at 17 16 01

I was expecting it to default to the current date/time instead of beginning of time.

And if I click on Confirm without selecting any date I get an error "Invalid date".

On Android I do not remember seeing this behaviour.

This is how I am currently solving the problem, but not sure if this is the best solution:

getDate(date = this.props.date) {
  if (date instanceof Date) {
    return date;
  } else {
    return date ? Moment(date, this.format).toDate() : Moment().toDate();
  }
}

Any help is appreciated, thanks.

Choosing an interval of time with the date picker

Hello,
Thank you for the plugin.
I would like to be able to choose intervals of time of at least 15 minutes.

Any ideas on how to do that with the date picker ? Or any ideas to create such functionality ?

Thank you

Jeremie

SpinnerMode

Is there anyway to enable spinnermode in the android datepicker like in the react-native original datepicker?

option Icon

Hi,

I hope to hide calendar icon, and it could be done by using customStyle={{ dateIcon: { width: 0, height: 0} }}. But it would be great if there's property like 'showIcon' to hide .

Nothing changed + calendar showing

Hi,
I'm raising an issue, maybe from my bad understanding of the doc ; but first of all: thank you for your work!

(Android)
I was very please by your example because I want to be able to choose the day - month - year in order to fill a "date of birth". And I want to fill it the same way as displayed in your example.

Unfortunately when I integrate your DatePicker into my react container the only thing displaying is the calendar and I can't even choose the year.
If I try to modify the buttons:
confirmBtnText="asfs" the confirm button under the calendar will always be "ok".

So, am I missing something? How can I have the same DatePicker as in your GIF? How can I change the confirmBtnText?

My code is just a copy past of your usage as I wanted to try it before "putting my hand in it".

    <DatePicker
        style={{width: 250}}
        placeholder="select date"
        format="DD-MM-YYYY"
        confirmBtnText="Confirm"
        cancelBtnText="Cancel"
        onDateChange={(userAge) => {this.setState({userAge})}}
    />

Many thanks!

Breaks on android

Running into this issue below:

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.SimpleMonthView.getMonthHeight()' on a null object reference
                                                                      at android.widget.DayPickerView.onLayout(DayPickerView.java:229)
                                                                      at android.view.View.layout(View.java:16630)
                                                                      at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                      at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                      at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                      at android.view.View.layout(View.java:16630)
                                                                      at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                      at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
                                                                      at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
                                                                      at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
                                                                      at android.view.View.layout(View.java:16630)
                                                                      at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                      at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                      at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                      at android.view.View.layout(View.java:16630)
                                                                      at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                      at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                      at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                      at android.view.View.layout(View.java:16630)
                                                                      at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                      at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                      at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                      at android.view.View.layout(View.java:16630)
                                                                      at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                      at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
                                                                      at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
                                                                      at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
                                                                      at android.view.View.layout(View.java:16630)
                                                                      at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                      at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                      at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                      at android.view.View.layout(View.java:16630)
                                                                      at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                      at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                      at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                      at android.view.View.layout(View.java:16630)
                                                                      at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                      at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                      at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                      at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
                                                                      at android.view.View.layout(View.java:16630)
                                                                      at android.view.ViewGroup.layout(ViewGroup.java:5437)
                                                                      at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2171)
                                                                      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1931)
                                                                      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
                                                                      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
                                                                      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
                                                                      at android.view.Choreographer.doCallbacks(Choreographer.java:670)
                                                                      at android.view.Choreographer.doFrame(Choreographer.java:606)
                                                                      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
                                                                      at android.os.Handler.handleCallback(Handler.java:739)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                      at android.os.Looper.loop(Looper.java:148)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Only on Android, the module works well on iOS. The error seems to trigger after tapping the datepicker button. Thanks in advance!

specs:
Android: M
react: 15.2.1
react-native: 0.30.0

Date text not change after i select a different date,

Maybe when i take the DatePicker into view and then this view is include in a state variable then render. date text not change after i select a different date. then i modify some code . it is working now. following are the modify.

//add a state variable that dateStr
this.state = {
      date: this.getDate(),
      modalVisible: false,
      disabled: this.props.disabled,
      animatedHeight: new Animated.Value(0),
      dateStr: this.props.date,
    };
//reset the value of dateStr
  getDateStr(date = this.props.date) {
    if (date instanceof Date) {
      let dateStr = Moment(date).format(this.format);
      this.setState({
        dateStr: dateStr
      });
      return Moment(date).format(this.format);
    } else {
      let dateStr = Moment(this.getDate(date)).format(this.format);
      this.setState({
        dateStr: dateStr
      });
      return dateStr;
    }
  }
 getTitleElement() {
    const {date, placeholder} = this.props;
    if (!date && placeholder) {
      return (<Text style={[Style.placeholderText, this.props.customStyles.placeholderText]}>{placeholder}</Text>);
    }
//direct to use the state value not the function before.
    return (<Text style={[Style.dateText, this.props.customStyles.dateText]}>{this.state.dateStr}</Text>);
  }

How to disable?

I want to disable the component, but no attr can set to it? any one who have sulotion?

Custom Calendar

Hi,

Great calendar picker!! But on iOS the Accept and Cancel option are on Chinese language.

Can you give the option for translate it or take the OS language.

And if you could add option to custom the calendar icon i will love you!

Thanks

How i get the value of the input?

Hello,
how can i get the value of the input after i click "submit" on my form?
i use it like this:

const DatePicker = require('./DatePicker');
<DatePicker />

Option for border box and icon position

Hi,

Could you add the option for put icon on left of date box. And for delete border or change style of date box?

PD: On iOS the DatePicker dont adjust to screen size.
You can put the property width for send Dimensions.width

Thanks!

How to remove the border?

Hi, thanks for the great work!

I am curious about the customStyles prop. Is this how I can remove the gray border around the date text as well as the calendar icon? How do I use it?

fix it in iOS

it'll be better if you add a style={{flex:1}} in line 224 in index.js

iOS: Animate the Picker Off-Screen

The Picker will animate onto the screen when invoked with a smooth transition, however, when the modal is dismissed through either Cancel / Confirm / clicking on the backdrop, it instantly flashes / disappears off-screen.

It should instead animate off the screen with the exact but inverted animation that was used to bring it onto the screen.

Ability to Customize Cancel & Confirm

Users may want to customize these buttons. I certainly do. Rather than accepting strings only, would be great if it also accepted React elements for these two. This way, you can pass in your own <Text></Text>, or <Icon />, or what have you.

screen_shot_2016-11-23_at_4_46_59_am

Right now, validation fails if you pass in a <Text></Text>.

screen shot 2016-11-23 at 4 49 54 am

Calendar DatePicker vs. Dial DatePicker

I noticed that in the animated example that the DatePickers open a three dial modal. However, when I tried using this library on my own device it uses a calendar modal. Is there any way I can change the mode to support the dial modal ?

Element type is invalid

I have the following code.

class DateTester extends Component {

  render() {
    return (
      <DatePicker
        style={{width: 200}}
        date="2016-05-01"
        mode="date"
        placeholder="select date"
        format="YYYY-MM-DD"
        minDate="2016-05-01"
        maxDate="2016-05-15"
        confirmBtnText="OK"
        cancelBtnText="Cancel"
        onDateChange={(date) => { let dob = date; }}
      />
    );
  }
}

I'm getting the following error
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of DateTester.

Any idea what's missing?

Programatically Open DatePicker

I have several situations where I want to open the DatePicker on mount, or open it via onPress of another component. Is there a way to programmatically call the opening of the DatePicker, perhaps through a ref?

Feature: Custom Design

Possible to use an own design and only use the 'modal' selector or be able to override the design by

<DatePicker
  date={this.state.date}
  mode="date"
  onDateChange={(date) => {this.setState({date: date})}}
>
  <Text>Adding my custom design, button and icons</Text>
</DatePicker>

placeholder is broken

if date is not specified the current date is placed by default instead of the placeholder, so placeholder is useless. We actually need it.

set time with keyboard

Hello,
i want to set time with keyboard.
For example, "08:30"
When i click 08 or 30, keyboard should open so i can set time with input value
Is there any way to do that?
Thank you!

Ignoring change in props (format / duration / etc.)

@xgfe Hey,
First of all thanks for writing this cool Date Picker :)

Looks like in the constructor you assign some props to instance variables that you later use in your code, that causes changes in these props to be ignored by code that runs after the change.

Any chance you could fix that?

Thanks,
kfir

It doesn't work on iOS

After update to
"react": "^15.2.0",
"react-native": "^0.28.0"
it shows empty datepicker on iOS.

点击确定按钮没反应

点击确定按钮不触发onDateChange方法,只是在非常少的情况下才会触发,在iOS真机和模拟器上都这样

It works well on IOS portrait but crash on landscape

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [RCTModalHostViewController shouldAutorotate] is returning YES'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.