Skip to content
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

Cordova app (iOS) returning from background has incorrect timestamp for touch events #19

Closed
tomhicks-bsf opened this issue May 19, 2015 · 4 comments

Comments

@tomhicks-bsf
Copy link

This is not the fault of this library, but seemingly a bug in UIWebView, but I thought it would be worth recording here (and possibly implementing a workaround in the plugin) to save someone else 2 days of their life.

In short, when a Cordova app returns from some particular background state in iOS, the timestamps on touch events are offset by the amount of time the app has been in the background. This means that the cancelling of mouse events doesn't work, because the time delta between last touch and current mouse event is like 3 minutes, instead of 300ms!

We figured out a workaround, which is to use Date.now() instead of nativeEvent.timeStamp when recording the lastTouchEvent time.

I've a few ideas about how this could be incorporated into this plugin:

  1. Just always use Date.now() when recording the last touch timestamp
  2. Make the tap event plugin into a function that takes a timeStampResolver as a function, and have a different version of the injector that passes in Date.now as the resolver for use in Cordova apps.
  3. Make the timestamp getter into a public function so the TapEventPlugin can be monkey-patched on an app-by-app basis.

Thoughts @s0meone?

@s0meone
Copy link

s0meone commented May 20, 2015

This time delta only occurs for touch events? The following click event has a correct timestamp?

It sounds like a bug indeed, when it's only for touch events. In that case, we could use Date.now() instead of .timeStamp.

@tomhicks-bsf
Copy link
Author

Yeah you get a delta of like 2 minutes between the touch and the click!

@s0meone
Copy link

s0meone commented May 20, 2015

OK, weird. I'll try to confirm your issue later in a UIWebView. I just tried it in a WKWebView and I'm not seeing this issue. Maybe you could use something like https://github.com/Telerik-Verified-Plugins/WKWebView in the main time?

@tomhicks-bsf
Copy link
Author

We've only tried it in UIWebView. We're not the only ones who've noticed the problem: http://stackoverflow.com/questions/26177087/ios-8-mobile-safari-wrong-timestamp-on-touch-events

It's a crazy bug!

dieppe pushed a commit to jnuine/react that referenced this issue Jul 6, 2015
This is a bad fix imo, because the problem lies more in the
discrepancies between the React Native events and the W3C events.

But at least it allows us to use the responder plugin…

Also note that using event.timeStamp can be problematic on iOS 8
webview, as seen here:
zilverline#19
madjam002 pushed a commit that referenced this issue Feb 3, 2016
It is not consistent across browsers. Fixes #19.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants