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

Prevent ng-click When Scrolling #745

Closed
calendee opened this issue Mar 7, 2014 · 24 comments
Closed

Prevent ng-click When Scrolling #745

calendee opened this issue Mar 7, 2014 · 24 comments
Assignees
Milestone

Comments

@calendee
Copy link

calendee commented Mar 7, 2014

When scrolling a list, items with ng-click are firing the click event. They really should not fire as this was a scroll rather than a click / tap.

Example : http://codepen.io/calendee/pen/yqefG

Reference : http://forum.ionicframework.com/t/disable-click-onscroll-list/1334

@adamdbradley adamdbradley added scroll and removed tabs labels Mar 8, 2014
@adamdbradley adamdbradley added this to the 1.0 Beta2 milestone Mar 8, 2014
@adamdbradley adamdbradley self-assigned this Mar 8, 2014
@emonidi
Copy link

emonidi commented Mar 10, 2014

http://docs.angularjs.org/api/ngTouch may help you. It handles ng-click as it is supposed to be handeled on mobile devices and alswo gives you ngSwipe directives as a bonus...:) Would be a good idea to be incorporated if it has not been done already...:)

@perrygovier
Copy link
Contributor

Seeing this quite a bit on Android KitKat devices. Its to the point on those devices that the app is unusable.

@adamdbradley
Copy link
Contributor

Thanks for reporting that @perrygovier, I'll be sure to heavily test my fixes on Android 4.4.

@perrygovier
Copy link
Contributor

A little more info: I'm not seeing this when using ionic scrolling (but I do see slightly choppy animation then), only when I set the overflow-scroll="true" option. Adding ngTouch appears to have no affect though.

@adamdbradley
Copy link
Contributor

Right now I do not recommend using ngTouch, and I blogged about it here: http://ionicframework.com/blog/hybrid-apps-and-the-curse-of-the-300ms-delay/

@perrygovier
Copy link
Contributor

Could the KitKat problem be related to Chrome 32+? Applying fastclick logic when they're no longer necessary?
http://updates.html5rocks.com/2013/12/300ms-tap-delay-gone-away

@adamdbradley
Copy link
Contributor

I committed a change to the nightly build to fix this issue. Would you be able to test it out with the latest nightly build and let me know if its working for you now? Thanks
http://code.ionicframework.com/#nightly

@calendee
Copy link
Author

This seems to have done the trick.

Scrolling no longer fires the ng-click.
Clicking works properly.

Sample : http://codepen.io/calendee/pen/osrLH

Thanks Adam!

Will consider closed.

@calendee
Copy link
Author

calendee commented Apr 8, 2014

Unfortunately, this issue has cropped up again.

See this sample : http://codepen.io/calendee/pen/gHxde

If you scroll or swipe, ng-click fires.

@calendee calendee reopened this Apr 8, 2014
@adamdbradley
Copy link
Contributor

I just quickly checked and this isn't an issue with touchmove, but only mousemove. Can you double check that?

Right now this is a design decision due to the fact that scrolling a webpage by holding the mouse down is not natural way to scroll on desktop, where as it is for touch. The main reason for not supporting mousemove canceling a click is due to Android firing both touchmove and mousemove events.

@calendee
Copy link
Author

calendee commented Apr 8, 2014

Interestingly, I just checked this on device and browser with the nightlies. The ng-click is not firing on device or browser with scroll attempts.

So.... all good?

@DruRly
Copy link

DruRly commented Apr 17, 2014

The latest works for me. Thx.

@adamdbradley
Copy link
Contributor

I just pushed a large tap refactor to solve many of these issues:
https://github.com/driftyco/ionic/blob/master/test/unit/angular/service/tap.unit.js#L4

Would you be able to test the nightly build (1712 or later) and let us know if it solved this issue?
http://code.ionicframework.com/#nightly

Thanks

Related: #862 #740 #726 #691 #689 #365 #26 #1134 #1120 #1105 #1078 #772 #745

@calendee
Copy link
Author

Just testing on iOS. ng-click events don't work on device anymore. Works fine in chome.

Tested with the side menu demo app and this code:

<ion-view title="Playlists">
  <ion-nav-buttons side="left">
    <button menu-toggle="left" class="button button-icon icon ion-navicon"></button>
  </ion-nav-buttons>
  <ion-content class="has-header">
    <ion-list>
      <ion-item ng-click="clickEvent()">Click Me</ion-item>

      <ion-item ng-repeat="playlist in playlists" href="#/app/playlists/{{playlist.id}}">
        {{playlist.title}}
      </ion-item>
      <ion-item ng-click="clickEvent()">Click Me</ion-item>
      <ion-item ng-click="clickEvent()">Click Me</ion-item>
      <ion-item ng-click="clickEvent()">Click Me</ion-item>
      <ion-item ng-click="clickEvent()">Click Me</ion-item>
      <ion-item ng-click="clickEvent()">Click Me</ion-item>
      <ion-item ng-click="clickEvent()">Click Me</ion-item>

    </ion-list>
  </ion-content>
</ion-view>

.controller('PlaylistsCtrl', function($scope) {
  $scope.playlists = [
    { title: 'Reggae', id: 1 },
    { title: 'Chill', id: 2 },
    { title: 'Dubstep', id: 3 },
    { title: 'Indie', id: 4 },
    { title: 'Rap', id: 5 },
    { title: 'Cowbell', id: 6 }
  ];

  $scope.clickEvent = function() {
    alert('Clicked!');
  }
})

@calendee
Copy link
Author

One problem. Scrolling on these list items now highlights them during the scroll event. This problem came up a while back but then got solved. It's back.

What a nightmare y'all must be going through trying to get it to work everywhere. Fix here, breaks there. Whack-a-mole! Sorry guys.

@adamdbradley
Copy link
Contributor

@calendee When I click the "click me" events in iOS7 I get the alert, but any of the ng-repeat items do not click because there's no ng-repeat directive on them.

Also, when tap and hold one of the items it turns gray, then when I scroll farther than 6px the gray goes away. You're saying that's not happening?

@perrygovier
Copy link
Contributor

Substantially better! I'm not seeing the highlight problem when I upgrade my CSS as well as the JS. The grey color is removed after a bit of scrolling. There's some choppiness on my 4s, but very minor. Also, when pages load, and I start dragging right away (before the event handler binds, I presume), I have to release and start dragging again before the drag takes hold.

There's a very noticeable problem I'm seeing where pages show up blank every other time I navigate to them, but that's another ticket.

@calendee
Copy link
Author

@adamdbradley I didn't notice that the highlight disappears after a bit of scroll. It does work though. Excellent. So I'm going to go ahead and close this. Thanks for the great work.

@udeeps
Copy link

udeeps commented Jan 8, 2016

@adamdbradley , I am using ionic v1.1.1. The list item doesn't get highlighted when I try scrolling in Google Chrome. But when I run the app in Galaxy S4, Android 4.4.2, the item gets highlighted for a while when I scroll. The flicker is kind of distracting. However, it doesn't behave so in iPhone 6. The scroll would have looked smoother if that highlight wouldn't trigger. Is there any way to achieve this?

@cityzen
Copy link

cityzen commented Apr 2, 2016

I'm seeing this issue as well on a Nexus 5 with KitKat 4.4.3 and iphone 6 with ios 9.3.1. I am wrapping the whole list item as a link so the link area is fairly large. Either way, it is quite distracting while scrolling through items.

@EmreErdogan
Copy link

EmreErdogan commented Jan 27, 2017

I'm seeing the issue, too. Tested on iPhone 6 with iOS 10.2.1
I am using ionic bundle version is 1.3.2.
I am also using cordova-plugin-crosswalk-webview@2.1.0 plugin.

For a workaround, I am using the solution offered in the following issue comment: #1438 (comment)

But the above workaround works only for list items. Of course it can be expanded to other elements, but you must bind the event handler to every clickable element in the page. Because every clickable element receives the click event when scrolling.

I am looking for a general approach that will apply to the whole application without code repetition.

Any ideas?

@nidhi42
Copy link

nidhi42 commented Dec 29, 2017

can you all please help it out to find solution

@EmreErdogan
Copy link

The following solution may help: #1438 (comment)

@ionitron-bot
Copy link

ionitron-bot bot commented Sep 1, 2018

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants