-
Notifications
You must be signed in to change notification settings - Fork 26
Delegates
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.
GestureDelegate instances can override its shouldReceiveTouch method or assign gesture filters:
shouldReceiveTouch: function(gesture, view, event) { return true; }
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() {}
});
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]
});