Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.

Delegates

ppcano edited this page Aug 14, 2012 · 11 revisions

Purpose

Delegates provides a mechanism to customize the gesture-recognition behavior based on the application state.

Delegates allow to create coordinated UIs to deliver a better UX.

When a Gesture has assigned a GestureDelegate, the gesture manager will use its delegate filters and shouldReceiveTouch method to decide if the gesture is recognized or not.

SetUp

GestureDelegate instances can override its shouldReceiveTouch method or assign gesture filters:

shouldReceiveTouch: function(gesture, view, event) { return true; }

Example

App.gestureDelegate = Em.GestureDelegate.create({
  name: 'gd1',
  popUpView: null,
  shouldReceiveTouch: function(gesture, view, event) {
      var popup = this.get('popUpView');
      return ( popup ) ? ( popup === view ) : false;    
  }
});

Add the created instance to the delegate list.

Em.GestureDelegates.add(App.gestureDelegate);

Setup your gesture to use the specific delegate.

App.popUpView = Em.View.create({
   tapOptions: {
       delegateName: 'gd1'
   },
   tapEnd: function() {}
});

Gesture Filters

If a gesture has assigned gesture filters, the gesture manager will iterate the filters calling for each filter its shouldReceiveTouch method, when a filter returns a value different than undefined, this output will be used as a gesture recognition outcome.

App.gestureDelegate = Em.GestureDelegate.create({
  name: 'gd',
  filters: [App.SettingDelegateFilter, App.PopUpDelegateFilter, App.ScreenDelegateFilter]
});
Clone this wiki locally