Open elsieclark opened 5 years ago
@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 this.state.initialized
. My result is shown in this PR for another component but the owner of that library quite reasonably does not want to merge the workaround. It needs to be fixed here, probably in native code, which I'm not particularly proficient at.
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.
If you install from my PR (not sure when or if it'll ever get merged), you'll get auto-linking in RN >= 0.60.0
yarn add 4Catalyzer/react-native-countdown-picker#pull/3/head
The workaround doesn't work for me... Any news on this? For the time being I've switched to: https://github.com/uraway/react-native-simple-time-picker
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
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!
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
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