Browse Source

fix: `minimumDate` and `maximumDate` with (milli)seconds prevents onChange to be called (#760)

master
Jason Yau 1 year ago
committed by GitHub
parent
commit
0151e2ccb3
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions
  1. +8
    -0
      .maestro/minimum-date.yml
  2. +15
    -1
      src/DatePickerAndroid.js

+ 8
- 0
.maestro/minimum-date.yml View File

@ -29,6 +29,14 @@ tags:
- runFlow: utils/swipe-wheel-3-up.yml
- assertVisible: '2000-01-01 23:59:00'
### test: should ignore seconds and milliseconds
- runFlow:
file: utils/change-minimum-date.yml
env:
VALUE: '2000-01-01 23:59:59.999'
- runFlow: utils/swipe-wheel-2-up.yml
- assertVisible: '2000-01-01 23:59:00'
### test: date mode
- runFlow: utils/change-mode-date.yml

+ 15
- 1
src/DatePickerAndroid.js View File

@ -27,7 +27,14 @@ class DatePickerAndroid extends React.PureComponent {
if (props.modal) return null
return <NativeComponent {...props} onChange={this._onChange} />
return (
<NativeComponent
{...props}
maximumDate={this._withoutSecond(props.maximumDate)}
minimumDate={this._withoutSecond(props.minimumDate)}
onChange={this._onChange}
/>
)
}
getId = () => {
@ -110,6 +117,13 @@ class DatePickerAndroid extends React.PureComponent {
this.isClosing = true
this.props.onCancel()
}
_withoutSecond = (date) => {
if (!date) return date
date.setSeconds(0)
date.setMilliseconds(0)
return date
}
}
export default DatePickerAndroid

Loading…
Cancel
Save