react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[DatePickerIOS] Warnings failed propType unexpected

Open ghamaide opened this issue 10 years ago • 13 comments

I'm currently trying out the DatePickerIOS and this simple example throws two warnings :


constructor(props) {
  super(props);

  this.state = {
    timeZoneOffsetInHours: (-1) * (new Date()).getTimezoneOffset() / 60,
    date: new Date(),
    color: '#007AFF',
    minimumDate: this.props.minimumDate,
  }
}

onDateChange = (date) => {
  this.setState({date: date});
};

render () {
  return (
    <View style={styles.basicContainer}>
      <DatePickerIOS
        date={this.state.date}
        mode="datetime"
        timeZoneOffsetInMinutes={this.state.timeZoneOffsetInHours}
        onDateChange={() => this.onDateChange}
        minimumDate={this.state.minimumDate}
       />
    </View>
  );
};

I'm getting these warnings :

2016-03-03 09:32:58.829 [warn][tid:com.facebook.React.JavaScript] Warning: Failed propType: Invalid prop `date` of type `Number` supplied to `RCTDatePicker`, expected instance of `Date`. Check the render method of `DatePickerIOS`.
2016-03-03 09:32:58.830 [warn][tid:com.facebook.React.JavaScript] Warning: Failed propType: Required prop `onDateChange` was not specified in `RCTDatePicker`. Check the render method of `DatePickerIOS`.

I did aconsole.log(this.props) in react-native's file DatePickerIOS.ios.js in Libraries/Components and the output is the following :

{ date: Thu Mar 03 2016 09:32:58 GMT+0100 (CET),
  mode: 'datetime',
  timeZoneOffsetInMinutes: 1,
  onDateChange: [Function],
  minimumDate: undefined }

Any chances I'm doing this wrongly ?

ghamaide avatar Mar 03 '16 08:03 ghamaide

+1 Getting the same error.

nHiRanZ avatar Mar 03 '16 09:03 nHiRanZ

@facebook-github-bot label iOS

brentvatne avatar Mar 06 '16 23:03 brentvatne

@ghamaide - seems like a bug! if someone can investigate this it would be appreciated. It's worth trying the DatePickerIOS example in UIExplorer and ensuring that works as expected without warnings, if not then use that as the test case to fix.

brentvatne avatar Mar 06 '16 23:03 brentvatne

image

because of requireNativeComponent, the RCTDatePickerIOS will be verify props base on the DatePickerIOS.propTypes.

but using RCTDatePickerIOS in the DatePickerIOS#render() was wrong, the date is number, undefined the onChange

daifee avatar Mar 10 '16 14:03 daifee

Good discovery @epooren - that makes a lot of sense.

atticoos avatar Mar 10 '16 14:03 atticoos

image

i fixed it at my branch

daifee avatar Mar 10 '16 15:03 daifee

Would you mind opening a Pull Request with your changes? It'd be great to introduce a solution to this!

atticoos avatar Mar 10 '16 15:03 atticoos

I'm still having the warning. Why is the pull request closed?

evollu avatar May 16 '16 18:05 evollu

I implemented the pull request changes in my DatePickerIOS.ios.js and it didn't solve the problem. I now get:

JSON value '2016-05-17 20:24:59 +0000' of type NSDate cannot be converted to a date

Any other ideas how to make the DatePickerIOS component work? I'm on react-native v0.24.1

rosiakr avatar May 17 '16 21:05 rosiakr

@brentvatne If I make a pr so that datePicker can accept both a Number or a Date object and check the date to see if it can getTime would that be fine? This way the verification at the native level will be fine with the number

dozoisch avatar Jun 07 '16 17:06 dozoisch

+1

mhollweck avatar Jun 16 '16 09:06 mhollweck

Just started using the picker and also having the warning.

heatworld1 avatar Jun 21 '16 21:06 heatworld1

Hi there! This issue is being closed because it has been inactive for a while.

But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/datepickerios-warnings-failed-proptype-unexpected

Product Pains has been very useful in highlighting the top bugs and feature requests: https://productpains.com/product/react-native?tab=top

Also, if this issue is a bug, please consider sending a pull request with a fix.

mkonicek avatar Oct 27 '16 21:10 mkonicek