Binding gestures event handlers support added

This commit is contained in:
Vladimir Enchev
2015-05-13 10:53:08 +03:00
parent b3f386f11f
commit 9e7fbc8a92
2 changed files with 35 additions and 0 deletions

View File

@@ -109,6 +109,8 @@ export function setPropertyValue(instance: view.View, instanceModule: Object, ex
if (isBinding(propertyValue) && instance.bind) {
if (isEvent) {
attachEventBinding(instance, propertyName, propertyValue);
} else if (isGesture(propertyName, instance)) {
attachGestureBinding(instance, propertyName, propertyValue);
} else {
var bindOptions = bindingBuilder.getBindingOptions(propertyName, getBindingExpressionFromAttribute(propertyValue));
instance.bind({
@@ -185,6 +187,22 @@ function attachEventBinding(instance: view.View, eventName: string, value: strin
instance.on(observable.Observable.propertyChangeEvent, propertyChangeHandler);
}
function attachGestureBinding(instance: view.View, gestureName: string, value: string) {
// Get the event handler from instance.bindingContext.
var propertyChangeHandler = (args: observable.PropertyChangeData) => {
if (args.propertyName === "bindingContext") {
var handler = instance.bindingContext && instance.bindingContext[getBindingExpressionFromAttribute(value)];
// Check if the handler is function and add it to the instance for specified event name.
if (types.isFunction(handler)) {
instance.observe(gestures.fromString(gestureName.toLowerCase()), handler);
}
instance.off(observable.Observable.propertyChangeEvent, propertyChangeHandler);
}
};
instance.on(observable.Observable.propertyChangeEvent, propertyChangeHandler);
}
function isGesture(name: string, instance: any): boolean {
return gestures.fromString(name.toLowerCase()) !== undefined;
}