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

Buttons can be clicked even if touchmoves are thrown #1111

Closed
wants to merge 6 commits into from
Closed

Buttons can be clicked even if touchmoves are thrown #1111

wants to merge 6 commits into from

Conversation

jonzeper
Copy link
Contributor

Previous behavior would suppress Button clicks if any touchmove events are thrown. Some devices are super sensitive and throw touchmove events for even slight taps. So instead, let's track movement during touchmoves and allow clicks to happen if the touch does not move very far.

Fixes #1108

Tested on Android Jellybean, Windows Surface, iPad, and desktop browsers

Previous behavior would suppress Button clicks if any touchmove events are thrown. Some devices are super sensitive and throw touchmove events for even slight taps. So instead, let's track movement during touchmoves and allow clicks to happen if the touch does not move very far.

Fixes #1108
@heff
Copy link
Member

heff commented Mar 26, 2014

Very cool, thanks! I think what we might actually want to do is update emitTapEvents to do the same, and then update button to listen for its own tap events. emitTapEvents is relatively new and I think we just didn't get around to updating button to use it.
https://github.com/videojs/video.js/blob/master/src/js/component.js#L835

@jonzeper
Copy link
Contributor Author

Makes sense to me.. In the meantime, I can't help but tidy this up just a little

@jonzeper
Copy link
Contributor Author

Gah, broke the build. Will fix

} else if (firstTouch) {
// Some devices will throw touchmoves for all but the slightest of taps.
// So, if we moved only a small distance, this could still be a tap
// 44 pixels is somewhat abitrary, based on Apple HIG 44px min button size
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

44 seems reasonable. HammerJS uses 10px for another data point. I'm not sure what would be considered too much.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use 22px? Since we probably don't want to click a button if the finger was moved away from it? But I would not be opposed to 44px.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of erring on the smaller side and expanding if we need to. 22px sounds good. With 44, someone could touch the center of one button and move their finger completely over another button and have it still be a tap. That seems a little too forgiving.

@heff
Copy link
Member

heff commented Mar 31, 2014

Looking good to me, and great tests, thanks! I want to do a little manual testing myself to see how it feels before pulling this in.

@gkatsev, look good to you?

xdiff = event.touches[0].pageX - firstTouch.pageX;
ydiff = event.touches[0].pageY - firstTouch.pageY;
touchDistance = Math.sqrt(xdiff * xdiff + ydiff * ydiff);
if (touchDistance > 44) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this 44 should be a variable/constant.
@heff does vjs have a convention for constants like these?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reasoning behind that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like having numbers like these just sit around in the code, it starts creeping into "magic number" territory. Also, we might need/want this number elsewhere at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me. I dunno where's the appropriate place to define this constant though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't have plans to use it anywhere else yet or have need to configure it externally, I think you could just create a var at the top of this function to store the value. We can decide if there's a better global place later when it's needed. That's good enough for me at least. @gkatsev?

@gkatsev
Copy link
Member

gkatsev commented Mar 31, 2014

code looks good. Made a comment about making the distance be a constant.

@jonzeper
Copy link
Contributor Author

jonzeper commented Apr 2, 2014

I somehow just found out that this causes issues in iOS. It's now firing both clicks and taps, so the click handler gets run twice. :/ Looking into it

@jonzeper
Copy link
Contributor Author

jonzeper commented Apr 2, 2014

Should be fixed now

@heff
Copy link
Member

heff commented Apr 4, 2014

This is looking good to me. @gkatsev would you want to test this on any specific devices before pulling it in? @jonzeper what devices/versions were you able to test this on?

@gkatsev
Copy link
Member

gkatsev commented Apr 4, 2014

I'll give it a spin tomorrow. Maybe @paruls or @bcjwhisenant could help as well.

@heff
Copy link
Member

heff commented Apr 14, 2014

@gkatsev @paruls @BCjwhisenant, let me know if you've been able to look at this, or if you can soon.

@jrw95
Copy link
Contributor

jrw95 commented Apr 14, 2014

I haven't been able to look at this (first I saw it, to be honest), but I'd suggest looking at it in in a few different iOS (7.1 and 7.0.x, and 6.1.x if possible) and Android versions. On the desktop, I'd suggest that the pass include at least one flavor of IE, preferably the Surface IE in UI mode.

@paruls
Copy link

paruls commented Apr 15, 2014

Just finished testing this on a Surface, Android, and a few different iOS. It looks good!

@heff
Copy link
Member

heff commented May 7, 2014

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Touch events on Buttons
5 participants