xgfe / react-native-datepicker

react native datePicker component for both Android and IOS, useing DatePikcerAndroid, TimePickerAndroid and DatePickerIOS
MIT License
2.12k stars 726 forks source link

App crash when tapping DatePicker on Android 8.1 #342

Open nateblog opened 5 years ago

nateblog commented 5 years ago

The app crash when tapping the DatePicker on Android 8.1 version, it works fine on lower versions.

Using:

"react-native": "0.54.0", "react-native-datepicker": "1.7.0",

I do not know how to go about fixing this.

nateblog commented 5 years ago

I manage to fix the crash by changing the function getDate()

TO:

getDate(date = this.props.date) {
    const {mode, minDate, maxDate, format = FORMATS[mode]} = this.props;

    // date默认值
    if (!date) {
      let now = new Date();
      if (minDate) {
        let _minDate = this.getDate(minDate);

        if (now < _minDate) {
          return new Date(_minDate);
        }
      }

      if (maxDate) {
        let _maxDate = this.getDate(maxDate);

        if (now > _maxDate) {
          return new Date(_maxDate);
        }
      }

      return now;
    }

    if (date instanceof Date) {
      return new Date(date);
    }

    return Moment(new Date(date), format).toDate();
  }

for some reason the returned date needs to be wrapped in new Date();

Is there a decent way to sort this out?

RenanSanguinete commented 5 years ago

@nateblog solution worked for me

ravindranpandu commented 5 years ago

Hello, solution for people who landed here if your app crashes on tapping on the date-picker

The above two are the main reasons to make your app crash, apart from that you can use any format you want to display your date in the component using the format props, doesn't matter whether you have dash/hyphen.

atlj commented 2 years ago

this solved my issue

although this is from another package, the issue is the same.

Basically you have to display an empty text component over the datepicker. This blocks user from touching the whitespaces