Skip to content

Commit 384ba39

Browse files
author
Vladimir Enchev
committed
gesture binding fixed + test
1 parent f7d5d49 commit 384ba39

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

CrossPlatformModules.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
<TypeScriptCompile Include="apps\tests\ui\animation\animation-tests.ts" />
147147
<TypeScriptCompile Include="apps\tests\xml-declaration\inherited-base-page.ts" />
148148
<TypeScriptCompile Include="apps\tests\xml-declaration\inherited-page.ts" />
149+
<TypeScriptCompile Include="apps\ui-tests-app\pages\gesture-binding.ts" />
149150
<TypeScriptCompile Include="ui\animation\animation.d.ts" />
150151
<TypeScriptCompile Include="ui\animation\animation-common.ts">
151152
<DependentUpon>animation.d.ts</DependentUpon>
@@ -934,6 +935,7 @@
934935
<Content Include="apps\ui-tests-app\layouts\wrap.xml" />
935936
<Content Include="apps\ui-tests-app\pages\background.xml" />
936937
<Content Include="apps\ui-tests-app\pages\circle.xml" />
938+
<Content Include="apps\ui-tests-app\pages\gesture-binding.xml" />
937939
<Content Include="apps\ui-tests-app\pages\i86.xml" />
938940
<Content Include="apps\template-blank\app.css" />
939941
<Content Include="apps\template-hello-world\app.css" />
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import observable = require("data/observable");
2+
import gestures = require("ui/gestures");
3+
import pages = require("ui/page");
4+
5+
export function pageLoaded(args: observable.EventData) {
6+
var page = <pages.Page>args.object;
7+
page.bindingContext = { tapAction: tapAction, doubleTapAction: doubleTapAction };
8+
}
9+
10+
export function tapAction(args: gestures.GestureEventData) {
11+
console.log("tapAction")
12+
}
13+
14+
export function doubleTapAction(args: gestures.GestureEventData) {
15+
console.log("doubleTapAction")
16+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Page loaded="pageLoaded">
2+
<StackLayout>
3+
<Label text="Handlers as exports" tap="tapAction" doubleTap="doubleTapAction" />
4+
<Label text="Bound handlers" tap="{{ tapAction }}" doubleTap="{{ doubleTapAction }}" />
5+
</StackLayout>
6+
</Page>

ui/builder/component-builder.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ var DOCK = "dock";
3030
var LEFT = "left";
3131
var TOP = "top";
3232

33+
var eventHandlers, gestureHandlers = {};
34+
3335
export function getComponentModule(elementName: string, namespace: string, attributes: Object, exports: Object): definition.ComponentModule {
3436
var instance: view.View;
3537
var instanceModule: Object;
@@ -103,6 +105,8 @@ export function getComponentModule(elementName: string, namespace: string, attri
103105
}
104106
}
105107

108+
eventHandlers, gestureHandlers = {};
109+
106110
componentModule = { component: instance, exports: instanceModule, bindings: bindings };
107111
}
108112

@@ -180,34 +184,34 @@ export function setPropertyValue(instance: view.View, instanceModule: Object, ex
180184

181185
function attachEventBinding(instance: view.View, eventName: string, value: string) {
182186
// Get the event handler from instance.bindingContext.
183-
var propertyChangeHandler = (args: observable.PropertyChangeData) => {
187+
eventHandlers[eventName] = (args: observable.PropertyChangeData) => {
184188
if (args.propertyName === "bindingContext") {
185189
var handler = instance.bindingContext && instance.bindingContext[getBindingExpressionFromAttribute(value)];
186190
// Check if the handler is function and add it to the instance for specified event name.
187191
if (types.isFunction(handler)) {
188192
instance.on(eventName, handler, instance.bindingContext);
189193
}
190-
instance.off(observable.Observable.propertyChangeEvent, propertyChangeHandler);
194+
instance.off(observable.Observable.propertyChangeEvent, eventHandlers[eventName]);
191195
}
192196
};
193197

194-
instance.on(observable.Observable.propertyChangeEvent, propertyChangeHandler);
198+
instance.on(observable.Observable.propertyChangeEvent, eventHandlers[eventName]);
195199
}
196200

197201
function attachGestureBinding(instance: view.View, gestureName: string, value: string) {
198202
// Get the event handler from instance.bindingContext.
199-
var propertyChangeHandler = (args: observable.PropertyChangeData) => {
203+
gestureHandlers[gestureName] = (args: observable.PropertyChangeData) => {
200204
if (args.propertyName === "bindingContext") {
201205
var handler = instance.bindingContext && instance.bindingContext[getBindingExpressionFromAttribute(value)];
202206
// Check if the handler is function and add it to the instance for specified event name.
203207
if (types.isFunction(handler)) {
204208
instance.observe(gestures.fromString(gestureName.toLowerCase()), handler, instance.bindingContext);
205209
}
206-
instance.off(observable.Observable.propertyChangeEvent, propertyChangeHandler);
210+
instance.off(observable.Observable.propertyChangeEvent, gestureHandlers[gestureName]);
207211
}
208212
};
209213

210-
instance.on(observable.Observable.propertyChangeEvent, propertyChangeHandler);
214+
instance.on(observable.Observable.propertyChangeEvent, gestureHandlers[gestureName]);
211215
}
212216

213217
function isGesture(name: string, instance: any): boolean {

0 commit comments

Comments
 (0)