Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Fix issue with Jquery for ngMobile #3198

Closed
wants to merge 4 commits into from
Closed

Fix issue with Jquery for ngMobile #3198

wants to merge 4 commits into from

Conversation

ethanli83
Copy link

Issue:

I found that the ngClick directive does not work with touch events dispatched by JQuery.
JQuery will wrap touch events, and touches can only be found on originalEvent.
The touch event handlers in ngClick directive are not using the originalEvent but event instead,
so the touches these handlers use, are 'undifined'.

Also, I found browsers are quite sensitive with touch, when I just tap on my touch screen,
the browser will dispatch 'touchstart', 'touchmove', and 'touchend'. Since the touch move handler
also reset status, I never get my click handler triggered.

Fix:

Check if event has an originalEvent property, and use it instead if it is found.
Also I make touch end handler triggers click handler if the distance between touch start and touch end,
is within MOVE_TOLERANCE.

ethan.li and others added 3 commits July 11, 2013 17:00
    touch even handlers do not handle jquery wrapped events quite well

fix:
    check if the event is a jquery event (has originalEvent property)
    and replace event variable with the originalEvent
    browser dispatch 'touchmove' event when user tap on screen (browser or touch screen being sensitive)

fix:
    if the movement is within MOVE_TOLERANCE, trigger clickHandler
@petebacondarwin
Copy link
Member

PR Checklist (Minor Bugfix)

  • Contributor signed CLA now or in the past (if you just signed, leave a comment here with your real name)
  • PR doesn't introduce new api
  • PR doesn't contain a breaking change
  • PR contains unit tests
  • PR contains e2e tests (if suitable)
  • PR contains documentation update (if suitable)
  • PR passes all tests on Travis (sanity)
  • PR passes all tests on ci.angularjs.org (cross-browser compatibility)
  • PR is rebased against recent master
  • PR is squashed into one commit per logical change
  • PR's commit messages are descriptive and allows us to autogenerate release notes (required commit message format)
  • All changes requested in review have been implemented

@petebacondarwin
Copy link
Member

@ethanli83 - can you please sign the CLA and read our commit message guidelines? Thanks

@ethanli83
Copy link
Author

I have done the online form few weeks ago.
My name is Chenguang Li.

@@ -221,7 +231,7 @@ ngMobile.directive('ngClick', ['$parse', '$timeout', '$rootElement',
var y = e.clientY;
var dist = Math.sqrt( Math.pow(x - touchStartX, 2) + Math.pow(y - touchStartY, 2) );

if (tapping && diff < TAP_DURATION && dist < MOVE_TOLERANCE) {
if (diff < TAP_DURATION && dist < MOVE_TOLERANCE) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This condition is important. touchend events can come following moves and other things that invalidate a straight-up-and-down tap, and the tapping flag is set on touchstart and cleared for those illegal motions.

As an example, without this, it's possible to put a finger down, move it two inches away, move it back so it's within the MOVE_TOLERANCE again, and release, triggering a tap.

Was this deliberately removed? If so, why? If not, please put it back when you squash into one commit.

@bshepherdson
Copy link
Contributor

I see from the description that you deliberately changed the tapping logic. I follow your argument, but the flag is still necessary, or new logic has to handle the bad case I outlined as well as your case.

What device is it where this unnecessary touchmove is getting included? I've mostly been testing on HTC One, Galaxy Nexus, Nexus 10, Nexus 7 and iPad Mini.

@ghost ghost assigned bshepherdson Jul 24, 2013
@ethanli83
Copy link
Author

Hi Braden,

I never thought about your case, and I think we need to handle that for
sure.

I am creating a kiosk app which is going to use a touch screen (dell
S2340T) rather than mobile device.

So the touch events are dispatched by desktop version of Chrome, and it is
quite sensitive on touch move (try changing Chrome:flags, but still really
sensitive) .

Maybe we do not resetStatus() on 'touchmove' until THRESHOLD exceed?

And sorry for these typos, I am quite famous with bad typing skill in my
team...

Ethan

On Thu, Jul 25, 2013 at 3:40 AM, Braden Shepherdson <
notifications@github.com> wrote:

I see from the description that you deliberately changed the tappinglogic. I follow your argument, but the flag is still necessary, or new
logic has to handle the bad case I outlined as well as your case.

What device is it where this unnecessary touchmove is getting included?
I've mostly been testing on HTC One, Galaxy Nexus, Nexus 10, Nexus 7 and
iPad Mini.


Reply to this email directly or view it on GitHubhttps://github.com//pull/3198#issuecomment-21502207
.

@bshepherdson
Copy link
Contributor

If I understand your suggested fix correctly, it should work. I was thinking of the same thing: rather than a touchmove always canceling the touch, check it against the MOVE_THRESHOLD. Once the difference from the start point gets big enough, cancel it.

Be sure to include some tests, for at least three cases:

  • normal touchmoves that move only slightly
  • touchmoves and touchend to outside the radius
  • touchmoves out and back, with the touchend inside the radius again

Thanks.

@ethanli83
Copy link
Author

Yep, exactly what I was thinking.
I will do that and make another pull request shortly.

Cheers

Ethan

On Thu, Jul 25, 2013 at 10:16 AM, Braden Shepherdson <
notifications@github.com> wrote:

If I understand your suggested fix correctly, it should work. I was
thinking of the same thing: rather than a touchmove always canceling the
touch, check it against the MOVE_THRESHOLD. Once the difference from the
start point gets big enough, cancel it.

Be sure to include some tests, for at least three cases:

  • normal touchmoves that move only slightly
  • touchmoves and touchend to outside the radius
  • touchmoves out and back, with the touchend inside the radius again

Thanks.


Reply to this email directly or view it on GitHubhttps://github.com//pull/3198#issuecomment-21525693
.

changes:
    1. in onTouchStart, only reset tapping to false if the it has moved outside the MOVE_TOLERANCE
    2. abstract repeat code into a function
    3. add tests for different touch scenarios
@ethanli83
Copy link
Author

hi @shepheb, I have made code changes base on our discussion.

I made the onTouchStart handler checks the distance between touch start and touch move and only reset tapping to false if it has moved out of the radius

I also add few more tests upon your suggestions

@ChristianWeyer
Copy link

Any idea when this fix will be merged?

@btford
Copy link
Contributor

btford commented Aug 21, 2013

Ping @shepheb: please provide a status update

@bshepherdson
Copy link
Contributor

LGTM.

@darrenahunter
Copy link

does that mean it will be in next 1.2 build

thanks

@ethanli83 ethanli83 closed this Sep 9, 2013
@kevin-smets
Copy link

Sooooo, this will be included in the next (rc) release? Sure hope so, I've rolled my own fastclick for now but I wouldn't mind to throw my code away for a properly integrated solution..

@ghost
Copy link

ghost commented Oct 21, 2013

This can't work because the touchEnd listener goes through the getSingleTouchLocation(event) function which doesn't look for changedTouches, so it always returns undefined for e.clientX/Y for touchEnd.

event = event.originalEvent || event;

// get the first touch object in the event
var touches = event.touches && event.touches.length ? event.touches : [event];
Copy link

Choose a reason for hiding this comment

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

This needs to be

var touches = (event.changedTouches && event.changedTouches.length) ? event.changedTouches :
 ((event.touches && event.touches.length) ? event.touches : [event]);

For this function to work.

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

Successfully merging this pull request may close these issues.

None yet

7 participants