googlearchive / polymer-gestures

84 stars 27 forks source link

Events are not dispatched properly #60

Closed sbmaxx closed 10 years ago

sbmaxx commented 10 years ago

How to reproduce:

Change

      events.forEach(function(en) {
        PolymerGestures.addEventListener(capture, en, function(inEvent) {
          appendOutput(inEvent.type + ' [' + inEvent.pointerId + ']');
          inEvent.preventDefault();
        });
      });

to

      events.forEach(function(en) {
        PolymerGestures.addEventListener(enterleave, en, function(inEvent) {
          appendOutput(inEvent.type + ' [' + inEvent.pointerId + ']');
          inEvent.preventDefault();
        });
      });

in samples/simple/index.html and open in any iOS device.

track event will not be fired.

Next do git checkout 39cf501f502a34ff2349dbef98c2eecf4fd6c93f^1 and try again. Everything should be OK.

Next do git checkout 39cf501f502a34ff2349dbef98c2eecf4fd6c93f and try again. Not working.

Something is broken in 39cf501f502a34ff2349dbef98c2eecf4fd6c93f

sbmaxx commented 10 years ago

Did some investigation. This is the problem code (src/dispatcher.js):

        if (this.IS_IOS) {
          var nodes = scope.targetFinding.path(inEvent);
          for (var i = 0, n; i < nodes.length; i++) {
            n = nodes[i];
            this.addGestureDependency(n, currentGestures);
          }
        } else {
          this.addGestureDependency(inEvent.currentTarget, currentGestures);
        }

In working case nodes are capture, body, html, document. Because targetFinding.path returns all nodes beginning from inEvent.target which is enterleave except enterleave itself. So when we do binds to capture, we catch event in enterleave, properly add dependency for it parent (capture) and all works correctly.

When we bind event to enterleave there are no addGestureDependency, because nodes are capture, body, html, document. And none of them has gesture dependency.

The possible workaround is to call addGestureDependency at inEvent.target node

          var nodes = scope.targetFinding.path(inEvent);
          this.addGestureDependency(inEvent.target, currentGestures);
          for (var i = 0, n; i < nodes.length; i++) {
            n = nodes[i];
            this.addGestureDependency(n, currentGestures);
          }
sbmaxx commented 10 years ago

@azakus take a look