Skip to content

DatepickerIOS onDateChange reports the wrong date #8169

@willmcneilly

Description

@willmcneilly

When using datepickerIOS the onDateChange callback sometimes reports the wrong date. By changing between date and month in quick succession you'll quickly find that the date reported by onDateChange is different from that shown on the datepicker. It's worth noting that the callback does fire correctly, it's just the date it provides is stale.

It's much easier to replicate on device but still possible on the simulator. Here's an example of the problem:
datepickerios

The code is straight forward:

class DatePickerBug extends Component {
  constructor(props) {
    super(props);
    this.state = {
      date: new Date()
    };
  }

  onDateChange(date) {
    this.setState({
      date: date
    });
  }

  render() {
    return (
      <View style={styles.container}>
        <Text>{this.state.date.toString()}</Text>
        <DatePickerIOS
          date={this.state.date}
          mode="date"
          onDateChange={(date) => this.onDateChange(date)}
        />
      </View>
    );
  }
}

We've noticed this issue in both 0.26 and 0.27. It didn't exist in 0.22 but because we upgraded our project in one move from 0.22 to 0.26 I'm unsure which version introduced the bug.

If anyone would like to get up and running with the example I have it here https://github.com/willmcneilly/RNDatepickerIOSBug

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions