Fix ios countdown
Summary
Fixes #30
The fix requires calling the setDate twice:
- the first time with a date that is different than what it will end up at
- the second time with the animated flag enabled and a copy of the final date
I've tried with only a single call or different not generating a copy of the date, but was only able to resolve it with this combination. These steps are wrapped in the method resetDate which gets called from willMoveToSuperview (the view may be displayed, so we're going to perform this resetDate here) and after the onChange handler is called and if we're using the countdown mode.
Test Plan
What's required for testing (prerequisites)?
A DateTimePicker component with 'countdown' mode running on an ios device or simulator:
<DateTimePicker
mode={'countdown' as any}
onChange={(event, date) => console.log('Updated!')}
value={new Date(0, 0, 0, hours, minutes, seconds)}
/>
What are the steps to reproduce (after prerequisites)?
Bug 1
- Add logging to
onChangehandler to produce visible output - Load up component in App
- Select the first value (notice onChange hasn't been triggered)
- Select another value (onChange will be triggered)
Bug 2
- Continuing from above
- Select 0 Hours, 0 Minutes (slider will automatically change to 1 minute and onChange handler should be triggered)
- Select another value other than 0 (notice onChange handler doesn't get triggered)
- Select a third value other than 0 (onChange will be triggered once again)
Compatibility
| OS | Implemented |
|---|---|
| iOS | ✅ |
This is an ios only bug. It shouldn't affect the existing android implementation.
Checklist
- [ x] I have tested this on a device and a simulator
- [ ] I added the documentation in
README.md - [ ] I updated the typed files (TS and Flow)
- [ ] I added a sample use of the API in the example project (
example/App.js) - [ ] I have added automated tests, either in JS or e2e tests, as applicable
I've tested this code and it does seem to fix the issue mentioned here, but another arises. The date defaults to 0 hours 1 minute on IOS so the date is invalid if no change is fired (no valid date on initialization)
hello @aceiii / @jsheffers would either one of you be able to address the issue found in the comment ^ and fix the PR or open another one? Thank you!
I'm trying to that other issue, but fixing that causes the other bug to pop up again. I'm stumped at the moment.