Open nateblog opened 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?
@nateblog solution worked for me
Hello, solution for people who landed here if your app crashes on tapping on the date-picker
minDate
and maxDate
value should always be a date
object for example: Tue Jul 09 2019 17:42:54 GMT+0900 (India Time Zone)
, if you use plain JS use new Date()
if you use moment use moment().toDate()
minDate
and maxDate
make sure that the maxDate
is not lesser than minDate
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.
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.