Android: onDateChange won't trigger when I select past 1 hour. but it was working fine if i select past more than 1 hour
Hi @TarunDas005. I don't manage to reproduce this, please provide example code which reproduces the issue.
@henninghall, I can also reproduce this and it happens only on Android.
For me it happens when changing specifically time picker's hour wheel on first render (so date is initially provided in code) from 11 AM to 12 PM (am/pm changes automatically) or 1PM to 12 PM.
Would be great if fix for this issue was released as a hot fix before migrating to RN 60.x.
@henninghall, Please check @Aurintas comments. I found this in the same scenario
@henninghall Another case is when changing time picker's hour wheel on the first render (so the date is initially provided in code) from 11 AM to 10 AM. Could you please fix this issue and update the library?
Thanks guys for further explanation. I will hopefully be able too look into it within a week. Please feel free to send a pull request if you find a solution yourselves!
@TarunDas @Aurintas I am still not able to reproduce it. Could you please provide a code sample? I have tried the following:
import React, { Component } from 'react';
import DatePicker from 'react-native-date-picker';
const initialDate = new Date()
initialDate.setHours(12)
export default class MinimalExample extends Component {
state = { date: initialDate }
render = () =>
<DatePicker
date={this.state.date}
onDateChange={date => {
this.setState({ date })
console.log("onDateChange", date);
}}
/>
}
@henninghall set DatePicker to mode="time" and try using this date as initial:
const initialDate = new Date("Mon Jul 29 2019 12:20:00 GMT+0300 (EEST)");
In this scenario, changing from 12 PM to 11 AM does not call onDateChange callback for me.
const initialDate = new Date("Mon Jul 29 2019 12:20:00 GMT+0300 (EEST)");
That line will still show different initial hour depending on the time zone you are in. I will appreciate if you can reproduce it by using for example initialDate.setHours(12) instead. Or tell me your time zone?
I still don't manage to reproduce it, let me once again ask again for a full sample? It would help a lot. Thanks.
"Europe/Vilnius" timezone, -180 offset
@Aurintas Still not getting it. I have sat Europe/Vilnius as my timezone and running following example:
import React, { Component } from "react";
import { Text, View } from "react-native";
import DatePicker from "react-native-date-picker";
const initialDate = new Date("Mon Jul 29 2019 12:20:00 GMT+0300 (EEST)");
export default class MinimalExample extends Component {
state = { date: initialDate };
render = () => (
<View>
<Text>{this.state.date.toISOString()}</Text>
<DatePicker
date={this.state.date}
mode="time"
onDateChange={date => {
this.setState({ date });
console.log("onDateChange", date);
}}
/>
</View>
);
}
Could you please confirm that you getting the error with that sample code?
@henninghall Thank you for taking time to look at this.
We've noticed that it depends on device time. Basically, it works incorrectly when you change hours wheel to currently set device time (hour).
So the issue is seen if it's 1 PM (device time), initial date is set to 2 PM and I scroll hours wheel to 1 PM (one step upwards). Same if it's 2 PM, initial date 3 PM and scroll to 2 PM. And so on.
This time issue persists even when using setHours on new Date().
@Aurintas Thanks for helping out investigating this. I now managed to track down the issue, will make a new release with this fix within a couple of days!
Released in v2.6.1