Closed hwde closed 5 years ago
Thanks for reporting this, I will have a look at it!
Any news about that....the library doesnt work
@LuisBonsembiante I haven't had time to look into this yet. Feel free to fix it yourself, pull requests are welcome 🙂
@LuisBonsembiante @hwde I have tried but I don't manage to reproduce the crash. Could you send the code of how you are using the component, including the props so I can try the same setup? Also, what version of the lib are you using?
I use version 2.3.0, this way:
constructor(props) {
super(props);
this.state =
{
value : this.props.value,
selectedValue : null,
};
}
renderPicker() {
return (
<DatePicker
date={this.state.selectedValue == null ? this.state.value : this.state.selectedValue}
onDateChange={date => this.onSelectValue(date)}
mode={'date'} />
);
}
And my component gets called with some date strings, i.e. "1999-12-24". I tried to debug the issue myself to write a pull request, but I was unable to "break" at a breakpoint inside java code. Will give it another try with a new sample project next days.
Funny, I am now able to "break" my app, the crash happens when "this" is a AmPmWheel, now at line Wheel.java#82:
if(picker.getValue() == 0) picker.setValue(index);
picker.getValue() is 0, and "index" is 0 too. But I can't see why picker.setValue(0) crashes. Maybe it is because a "AmPmWheel" is not visible when only "date" selection is done?
And my component gets called with some date strings, i.e. "1999-12-24".
Hmm, you should call the date picker with Date objects, not strings. Try changing it!
Since you are not using maximumDate, the default for date mode is 2100. Try to set maximumDate
prop to something higher if you expect values above 2100. For instance:
const maxDate = new Date(2110,1,1)
...
<DatePicker
maximumDate={maxDate}
...
... , but I was unable to "break" at a breakpoint inside java code.
If you are running the example app in this repo you need to set the breakpoints in example/node_modules/react-native-date-picker/android/...
picker.getValue() is 0, and "index" is 0 too. But I can't see why picker.setValue(0) crashes. Maybe it is because a "AmPmWheel" is not visible when only "date" selection is done?
Yeah probably.
Sorry, my mistake. I don't use strings for the value. I use something like: value={new Date("1999-12-24")}
I tried as you suggested and added the maximumDate={maxDate}, but it still crashes.
btw.: I now tried with:
const maxDate = new Date(); ... <DatePicker maximumDate={maxDate} ...
but it renders still with a maximum year of 2100, does maximumDate works with Android?
Yes maximumDate should be supported on android! Just to be sure, this code actually gets your app to crash?
const maxDate = new Date(2110,1,1)
export default class Example {
state = {
date: new Date(2100, 1, 1)
}
render(){
return (
<DatePicker
date={this.state.date}
maximumDate={maxDate}
mode={'date'}
setDate={date => this.setState({ date })}
/>
)
}
}
What phone model are you using? Thanks a lot for your help!
It looks like this is a react-native race-condition ... somehow. I am unable to reproduce it in a sample app. I need some time to look it more deeper. I'll get back asap.
Thanks a lot! 🙂
Since we are not able to reproduce this, I am closing this issue. I'll reopen if anyone finds a way to reproduce this in an example app.
It looks like the Picker can cause a NullPointerException if a "far future" date is picked, i.e. set the year to 2100 - maybe related to a Android/Java Date/Time limitation?. Maybe the issue is not the "pick" but the the update of the picker after the picked value has been send to the app.
Stack trace is: