mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Binding gestures event handlers support added
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user