mmazzarolo / react-native-modal-datetime-picker

A React-Native datetime-picker for Android and iOS
MIT License
2.96k stars 396 forks source link

Set currentDate to be prop.minimumDate if not null or the current date. #726

Open andvalsol opened 10 months ago

andvalsol commented 10 months ago

Overview

For iOS if the user hasn't touched the picker, the default date is set to be the date when the picker was mounted, instead of setting the date to be the minimum date (if passed), else the current date should be selected, since the mounting of the date could be at 11:59pm and the re-render could have been at 12:00am.

Test Plan

1) Open the picker on iOS 2) Set the minimum date to be a different date from the current date. 3) The picker's selected date (when clicking confirm) the returned should be the minimum date as expected, also the picker should behave as usual when other actions are taken.

mmazzarolo commented 10 months ago

Maybe I'm missing something but doesn't this defeat the purpose of having the date prop?

image
andvalsol commented 10 months ago

Maybe I'm missing something but doesn't this defeat the purpose of having the date prop?

image

I've added a change in the PR, this change corresponds to the behaviour the datetime picker seems to work on iOS

andvalsol commented 10 months ago

I've changed the PR.

mmazzarolo commented 10 months ago

Will review soon. FYI, this can also be done directly outside of the library:

setState({
  isPickerOpen: true, // var that drives the picker visibility
  pickerDate: date > minimumDate ? date : minimumDate // `date` prop passed to the picker
})
andvalsol commented 10 months ago

yes, but, well I feel that by doing this the library would match the behaviour of the modal in iOS, also the warning is quite handy 😄

andvalsol commented 9 months ago

@mmazzarolo have you got the chance to review the changes?

Saim-Nasser commented 1 month ago

Why isn't this being merged? This should be the default behavior.