emberjs-addons / ember-touch

A lightweight library for building and using touch gestures with Ember Applications
MIT License
182 stars 28 forks source link

Approach on event bubbling/preventDefault #13

Closed jschilli closed 11 years ago

jschilli commented 11 years ago

With ember master now dealing with return values from event handlers, ember-touch breaks in a way that is difficult to work around.

With two potentially overlapping views, both of which handle tapEnd for instance, the current implementation will trigger on both views.

It seems to me that this can be fixed in one of two ways.

  1. have touch{End,Cancel,Start} do the right thing and return true/false when the handler returns - currently it is 'undefined' -

or

  1. have attemptGestureDelivery and notifyViewOfGestureEvent pass the event into the gesture handler (e.g. tapEnd(recognizer,evt)

The 2nd approach would put control over calling preventDefault() in the hands of the view handling the event.

Either approach would work (I've implemented both and am currently using the 2nd approach with a fork of ember-touch)

Thoughts on a preferred way to handle this?

ppcano commented 11 years ago

I am still using 0.9.8.1, so i have still not experienced any problems. In order to advance development and support multiple ember versions, i have prepared the test suite to be run with multiple ember versions.

Regarding your proposals, i think we should follow/continue ember approach.

1) Second option, makes sense to me, so far the view can also access the event on other browser events ( click ....) and allow to use preventDefault/stopPropagation on the view to manage App UI logic. I think this feature just extend the api and does not break anything.

2) Event Bubbling is documented and the code can be easily read at the EventDispatcher.

The EventDispatcher executes the event stopPropagation method when it is handled with an eventManagers and does not bubble up it.

That's why bubbling up is done with the gestureManager.

So we could implement the same steps, if the view touchEvent method returns false or the evt has been stopped, the gestureManager must not bubble up.

I don't know if i could be missing something or being wrong with this approach, suggestions are wellcome, @jschilli let me know, if you want to Pull Request against master including some unit Tests.

ppcano commented 11 years ago

Your second option has been included in the following commit.

I am closing this issue.