question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onDateChange fires too slow, waits until animation is fully complete

See original GitHub issue

Hi, Sometimes there is a race condition between the user changing the Date and the user then clicking “Save” on my form, i.e., the user might hit Save when they think the date is already set, but actually the DatePicker’s animation is not yet complete and so the onDateChange has not yet fired. Anecdotally, I feel this gap can be almost 500ms sometimes. I think the issue is that a human can visually see from the animation that the scroller is clearly going to stop at the correct date, and then proceeds to click Save on the form.

Short of adding a 500ms delay to my Save action, I’m not sure what I can do to prevent this race condition.

Maybe you can consider firing the onDateChange even before the animation is fully complete, when you can predict what the value is going to end up being.

Alternatively, it would help if you can provide some way that I can know that the DatePicker is still in motion. Maybe even an initial onPress() callback would help me know the date picker is being used.

To Reproduce Add example code that reproduces the behavior.

 <DatePicker
              style={styles.input_date}
              date={formData.expiryDate}
              onDateChange={date => {
                console.log("UPDATED");
                setFormData(data => {return {...data, expiryDate: date}})}
              }
              androidVariant='nativeAndroid'
              mode="date"
              fadeToColor='#CCC'
              />

Smartphone (please complete the following information):

  • OS: Android
  • React Native version - 0.63.4
  • react-native-date-picker version 3.2.7

Thanks!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:7
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
suzaninficommented, Apr 4, 2022

Same issue here. It’s quite easy for a user to hit ‘save’ too early, while the picker is still ending its scroll animation. Visually it looks like the date already changed, but the picker did not fire onDateChange yet and a save action results in the old date. For me it would be very helpful if there was some way to know that the picker is still ‘busy’ scrolling, then I could disable the save button during this time for example.

1reaction
enervecommented, Jun 16, 2021

Maybe a simpler proposal would be to add an “onDateDisplayChange” event – this would fire every time (or almost every time) the date scroller visually “enters the region” of a new date/number (and not just when the date scroller has finally stopped scrolling). So for example if the date starts at “Jan 14 2021”, when the user starts scrolling the month towards “Apr”, this event would fire for “Feb 14 2021” and “Mar 14 2021” and finally “Apr 14 2021” the moment the scroller “enters” each of those. If the events are too spammy, perhaps you could set this to fire no more often than 100ms.

Let me know if i’m making any sense 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery animate()'s complete function fires before completion
You are calling the animation effect on 2 elements: html and body . This means the animation actually runs twice and the complete...
Read more >
How to know if animation has finished completely?
Using the AnimationTrack.Stopped event fires whenever the animation has stopped, for whatever reason (or am I wrong?) Like so:.
Read more >
Diff - caf7f3d1fc28f74f0782438cd5a91aef7a9dedb5^2 ... - Google Git
Creator CREATOR; field public static final int FULL = 4; ... Same for the changing animation when disappearing; it waits for the item...
Read more >
Android Tutorial
Early mobile phones were not particularly full featured. (Although, ... shows the dialog for waiting for the debugger to connect until you.
Read more >
Return Fire Animation still bugged after months
I know i might look stupid for being upset about it, but really, this still bothers me so much! Devs, please, a fix...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found