-
-
Notifications
You must be signed in to change notification settings - Fork 412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iOS DateTimePicker in countdown
mode fails to call onChange
on first update
#30
Comments
Includes workaround from react-native-datetimepicker/datetimepicker#30
@willdavidc Thanks for this workaround. It helps a lot, but unfortunately doesn't fix the problem completely. If the user spins the picker to 0 hours 0 minutes, iOS automatically changes it to 0 hours 1 minute, and onChange again doesn't fire the next time the user moves the picker. Example code here. |
@Swaagie Could someone take a look at this bug? The workaround suggested by @willdavidc helps, though it took me a lot of trial and error to figure out where to set and reset Thanks! |
I've switched to react-native-countdown-picker. It doesn't have this problem. Although the library hasn't been updated in a long time, it is a very simple wrapper around the ActionSheetPicker-3.0 pod, which is actively maintained.
|
The workaround doesn't work for me... |
A bit frustrating, but I have the workaround working for me. I'm using hooks and this is how I've set it up. Not amazing, but it's working well enough. // Variable to hold the time, set it to 1 minute
const [duration, setDuration] = useState(new Date(0, 0, 0, 0, 1, 0, 0))
const [hasLoaded, setHasLoaded] = useState(false)
useEffect(() => {
setTimeout(() => {
setHasLoaded(true)
}, 50) // I needed to include the timeout for this to work
}, [])
//...
<DateTimePicker
...
value={hasLoaded ? duration : new Date(0, 0, 0, 0, 1, 5)}
/>
// Other time probably doesn't have to be 5 seconds, but that's what I did |
this worked for me. Thanks a lot! |
worked for me but not very convenient as said above |
Thanks for this - I had to use it only in iOS 15. In my case, because my picker was in a modal, I have to do the "workaround" every time the modal was toggled. |
TLDR; This appears to have been fixed by Apple in iOS 16, so this can probably be closed. I ran across this again when I updated my app to RN 0.72. I had totally forgotten about it. (It's been a long time). I'm trying to support older versions of iOS, so tested with various simulators. The workaround described above seems to work up till iOS 16, after which it is no longer needed. In addition, I found that the other problem I reported above goes away in iOS 15. |
Bug
In
countdown
mode, the first time the value in the picker gets updated, theonChange
event isn't triggered. Every subsequent time, it is. Thedate
,time
, anddatetime
modes work fine.I found the following Stack Overflow thread which describes exactly the same problem, except just in Swift, no React Native. This leads me to think there's a problem with the underlying Swift API.
For anyone else who runs into this problem, I was able to get around it by updating the
value
prop at least once upon initialization, before the user has time to interact with it. Even changing thevalue
date by a single second seems to do the trick; I recommend that to avoid playing an animation on the update.Workaround:
Environment info
Library version: 2.1.0
Steps To Reproduce
mode
prop tocountdown
onChange
prop to something that should produce visible outputonChange
handler will not trigger.onChange
handler will trigger....
Describe what you expected to happen:
onChange
handler should update both times.Reproducible sample code
The text was updated successfully, but these errors were encountered: