React-native: [DatePickerIOS] minuteInterval not work with mode="time" minimumDate={min} maximumDate={max}

Created on 24 Aug 2016  路  25Comments  路  Source: facebook/react-native

render() {
let {year, month, day} = new Date();
let min = new Date(year, month, day, 8);
let max = new Date(year, month, day, 22);
return (
date={this.state.date}
mode="time"
minuteInterval={10}
minimumDate={min} maximumDate={max}
onDateChange={(date) => this.setState({date})}
/>);

I found that minuteInterval works on iOS emulator, but not work at real device both minuteInterval and date range feature.

Bug DatePickerIOS Locked

Most helpful comment

I found a workaround for this issue. In DatePickerIOS, set the minuteInterval prop to a local state.
e.g. minuteInterval={this.state.minuteInterval}
Then, in componentDidMount(), set this.state.minuteInterval to the desired minuteInterval.
e.g. componentDidMount() { this.setState({minuteInterval: 5}); }

All 25 comments

I have a same problem, but not work also my simulator. I'm use version 0.31

Ditto. I am running 0.33.0 and this does not work. I am not using min/max date either. Keeping it simple.

Confirming same issue.
Running Xcode 8.0,
React Native UIExplorer (master branch), with 10 minute interval
screen shot 2016-09-30 at 9 22 01 am

CalabashSmokeTest Native UIDatePicker with 30 minute interval
https://github.com/calabash/ios-smoke-test-app
screen shot 2016-09-30 at 9 19 36 am 1

@nicklockwood Do you think that your latest commit to the DatePicker could be preventing the minuteInterval prop from being set somehow? I wonder if there is something else going on here...

https://github.com/facebook/react-native/commit/c1aff6b116dd8ca42dd81ab59a542a3a6d18e46e#diff-bb7f9a35dd5ae2a59fcff0292caf41f3

@dsibiski yes, confirming that adding back width: 320 to datePickerIOS style does fix this issue.

Still an issue at RN 0.38 - minuteInterval isn't passed through in any combination of props.

I found a workaround for this issue. In DatePickerIOS, set the minuteInterval prop to a local state.
e.g. minuteInterval={this.state.minuteInterval}
Then, in componentDidMount(), set this.state.minuteInterval to the desired minuteInterval.
e.g. componentDidMount() { this.setState({minuteInterval: 5}); }

@MiLeung Thanks! That works great! 馃憤

@MiLeung sorry, that fix did not work for me.

It should be added to the issue that I only see this issue on my iPhone 5c, not my iPhone 6 or the simulator...

@albinhubsch (These are just ideas)

  • Is your 5c on the latest iOS?
  • Is your date picker component actually mounted before calling this.setState({minuteInterval: 5}); or are you returning null as a result of some logic in your render method?
  • What version of RN are you using? (I was using 39.2 when I found this workaround)

@MiLeung Ah, thanks! It was not mounted when setState was called 馃憤

I confirm @dsibiski workaround works on RN 0.37. Just add minWidth: 320 to the DatePickerIOS style.

Both workaround does't work for me in [email protected]

@tiaaaa123
@dsibiski workaround does work on RN 0.40 for me.
I think some better solutions without modifying native library should be conceived,
or it will be painful every time I upgrade RN to a new version.

@MiLeung method worked for me

@MiLeung your method worked for me on react-native v0.44.3. This is a nice workaround that doesn't involve hacking or forking the react-native libraries. Thank you for sharing!

Has anyone had any luck getting minuteInterval to work on RN >= 0.45? Setting fixed width worked for me up to RN 44, but something seems to have changed, such that neither of the above workarounds work anymore.

@wsun, MiLeung's workaround is working for me on RN = 0.48

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

Hey the previous workaround only worked for me when I added a constructor with a different value than the one inside the componentDidMount() method. I set it to 0 in the constructor and to 15 in the componentDidMount() which then worked.

@hugoh1995 what version of react native does it work in for you?

This is still an issue.

You can easily debug this by going to RNTester DatePickerExample and changing the type of last example to time only.

This is fixed in #23923. And will be included in a next release.

Was this page helpful?
0 / 5 - 0 ratings