Open jnrepo opened 8 years ago
Same here.. not working for android anymore.
I'm so sorry, but I can't replay your issue. Could you paste some code?
@feyy I\ve got this when working in customStyles, seems to work until now, maybe it was some color on a view or something. Also you could add more class examples in readme, like placeholderText: and the other ones in the code.
@feyy sorry, didn't have much time to get on my project with the code. but this is what is giving me the error:
<DatePicker
style={{
width: deviceWidth * 0.84,
left: 0.0781 * deviceWidth,
top: 0.5231 * deviceHeight,
position: 'absolute'
}}
date={this.state.birthday}
minDate={moment('1920-01-01').format('YYYY-MM-DD')}
maxDate={moment().format('YYYY-MM-DD')}
mode="date"
placeholder="Birthday"
format={DATE_FORMAT}
confirmBtnText="Confirm"
cancelBtnText="Cancel"
showIcon={false}
customStyles={{
dateText: {
color: '#ffffff',
textAlign: 'left',
marginBottom: 3
},
dateTouchBody: {
// color: '#ffffff',
alignItems: 'flex-start',
justifyContent: 'flex-end',
flexDirection: 'row',
borderColor: '#ffffff'
},
dateInput: {
width: deviceWidth * 0.835,
// color: '#ffffff',
left: 0.01 * deviceWidth,
alignItems: 'flex-start',
justifyContent: 'flex-end',
borderColor: '#ffffff',
borderTopWidth: 0,
borderRightWidth: 0,
borderLeftWidth: 0
},
placeholderText: {
color: '#ffffff',
marginBottom: 3
}
}}
onDateChange={(birthday) => {
if(birthday === 'Invalid date') {
birthday = moment().format(DATE_FORMAT)
}
this.setState({birthday})
}}
/>
@feyy alright, I was able to narrow down the issue after playing with the code a little bit. It seems that for android when the format doesn't have dashes (ie. "MMM DD YYYY", "MMMM DD YYYY", "MMM Do YYYY") it doesn't work. However, when the format is set to "MMM-DD-YYYY" it will work...
Hope that helps
@jnrepo It work for me. Could show your code?
<DatePicker
style={{
width: deviceWidth * 0.84,
left: 0.0781 * deviceWidth,
top: 0.5231 * deviceHeight,
position: 'absolute'
}}
date={this.state.birthday}
mode="date"
placeholder="Birthday"
format="MMM DD, YYYY"
confirmBtnText="Confirm"
cancelBtnText="Cancel"
minDate={moment('1920-01-01')}
maxDate={moment().format('YYYY-MM-DD')}
showIcon={false}
customStyles={{
dateText: {
color: '#ffffff',
textAlign: 'left',
marginBottom: 3
},
dateTouchBody: {
// color: '#ffffff',
alignItems: 'flex-start',
justifyContent: 'flex-end',
flexDirection: 'row',
borderColor: '#ffffff'
},
dateInput: {
width: deviceWidth * 0.835,
// color: '#ffffff',
left: 0.01 * deviceWidth,
alignItems: 'flex-start',
justifyContent: 'flex-end',
borderColor: '#ffffff',
borderTopWidth: 0,
borderRightWidth: 0,
borderLeftWidth: 0
},
placeholderText: {
color: '#ffffff',
marginBottom: 3
}
}}
onDateChange={(birthday) => {
if(birthday === 'Invalid date') {
birthday = moment().format("MMM-DD-YYYY")
}
this.setState({birthday})
}}
/>
^ will only work on iOS and will return the error in the OP for Android.
Using...
Android M react 15.2.0 react native 32.0
I got exact same error message in my Android app (a native Android app, not using ReactNative), this issue seems caused by the value of maxDate is smaller than the minDate, when the DatePickerDialog.show() calling, the app will raise this error and crashes.
Both minDate and maxDate in native Android API is long value contains the milliseconds level UNIX timestamp, print a log with these two values may help you find the reason of this issue.
You are right pengan , Also check the timestamp u are passing is in mili seconds or not ,I forgot to change it to mili seconds so it was giving me this problem.
I found the solution.
The date value format must be same from the maxDate format value and the format prop
// wrong date="07-01-2018" format="YYYY-MM-DD" maxDate="2018-07-01"
// good date={'2018-06-19'} format="YYYY-MM-DD" maxDate="2018-07-01"
I used moment and pass the format in props.
var today = new Date()
value={moment(props.value).format(props.format)}
format={props.format}
maxDate={moment(today).format(props.format)}
I got exact same error message in my Android app (a native Android app, not using ReactNative), this issue seems caused by the value of maxDate is smaller than the minDate, when the DatePickerDialog.show() calling, the app will raise this error and crashes.
Both minDate and maxDate in native Android API is long value contains the milliseconds level UNIX timestamp, print a log with these two values may help you find the reason of this issue.
Same here, pure native development. Saw the problem on a Nexus 7 tablet running 6.0.1
.
Fix applied: In my case, I was setting the maxDate
as Long.MAX_VALUE
just for the sake of it. I just removed that line and it worked just fine.
I suffered from same issue and removing maxDate
fix the problem.
Me it doesn't work. Please see my code: ` const ModalPicker = require("nativescript-modal-datetimepicker").ModalDatetimepicker; const picker = new ModalPicker(); const SQLite = require( "nativescript-sqlite" ); const kad = require('../js/myfonction'); const moment = require('moment'); var Toast = require("nativescript-toast"); var EventEmitter = require('events'); import { TNSFancyAlert, TNSFancyAlertButton } from "nativescript-fancyalert";
moment.locale('fr');
export default {
name: 'HomePage',
data(){
return{
madate: moment(new Date().toISOString()).format("LLLL"),
mine: '45',
my_db: null,
nb: ''
}
},
mounted(){
var clock = require('date-events')()
this.my_db = kad ;
clock.on('minute', function (min) {
console.log('Minute ' + min + ' has arrived!')
})
},
computed:{
epa(){
return this.mine;
}
},
methods: {
lancemoi() {
picker
.pickDate({
title: "Choisis la date à inscrire!",
theme: "light",
maxDate: new Date(),
minDate: new Date(moment().subtract(30, 'days').calendar())
})
.then(result => {
var carma = new Date(result.year+"-"+(result.month)+"-"+ result.day);
this.madate = moment(carma.toISOString()).format("LLLL");
//console.log("la date: "+ moment(carma.toISOString()).format("LLLL"));
})
.catch(error => {
console.log("Error: " + error);
});
},
insertData(){
if(this.madate != '' && this.nb != ''){
if(kad.Insert(this.madate,this.nb) == 1){
TNSFancyAlert.showSuccess(
"Enregistrement",
"Le champ a bien été enregistrée",
"Okay",
).then(()=>{
this.madate = '';
this.nb ='';
});
}else{
TNSFancyAlert.showError("Error!", "Le champ n'a pu etre inseré! .", "Fermer");
}
}else{
Toast.makeText("Veullez Choisir une date et un nombre").show();
}
},
selectData(){
kad.SelectAll();
}
}
};
`
Hey Guys, i had the same issue and was breaking my head for couple of days and finally fixed the issue, here is the fix for people who needs help in the android crash issue if your app crashes when you tap the datepicker.
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.
Hope this will make someone day better, cheers 😃
Running into this issue below:
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