Fixed issue with binding gestures to repeater items.

This commit is contained in:
Nedyalko Nikolov
2015-08-14 12:11:41 +03:00
parent 1f8bcc565c
commit 7e6afa603f
5 changed files with 53 additions and 1 deletions

View File

@@ -14,6 +14,9 @@ import labelModule = require("ui/label");
import textFieldModule = require("ui/text-field");
import fs = require("file-system");
import appModule = require("application");
import repeaterModule = require("ui/repeater");
import gestureModule = require("ui/gestures");
import layoutBaseModule = require("ui/layouts/layout-base");
// <snippet module="ui/core/bindable" title="bindable">
// For information and examples how to use bindings please refer to special [**Data binding**](../../../../bindings.md) topic.
@@ -528,6 +531,30 @@ export var test_BindingContext_NavigatingForwardAndBack = function () {
helper.navigateToModuleAndRunTest(("." + moduleName + "/bindingContext_testPage1"), null, testFunc);
}
export var test_RepeaterItemsGestureBindings = function () {
var testFunc = function (page: pageModule.Page) {
var repeater = <repeaterModule.Repeater>(page.getViewById("repeater"));
var hasObservers = false;
var eachChildCallback = function (childItem: viewModule.View) {
if (childItem instanceof labelModule.Label) {
var gestureObservers = childItem.getGestureObservers(gestureModule.GestureTypes.tap);
hasObservers = gestureObservers ? gestureObservers.length > 0 : false;
}
else if (childItem instanceof layoutBaseModule.LayoutBase) {
childItem._eachChildView(eachChildCallback);
}
return true;
}
repeater._eachChildView(eachChildCallback);
TKUnit.assertEqual(hasObservers, true, "Every item should have tap observer!");
}
var moduleName = __dirname.substr(fs.knownFolders.currentApp().path.length);
helper.navigateToModuleAndRunTest(("." + moduleName + "/repeaterItems-bindingToGestures"), null, testFunc);
}
export var test_BindingToSource_FailsAfterBindingContextChange = function () {
var createLabel = function () {
var label = new labelModule.Label();

View File

@@ -0,0 +1,14 @@
function pageLoaded(args) {
var page = args.object;
page.bindingContext = {
items: [
{ text: "1", tapItem: function () { console.log("1") } },
{ text: "2", tapItem: function () { console.log("2") } }
]
};
}
exports.pageLoaded = pageLoaded;
exports.tapPage = function (args) {
console.log("Tap! " + args + " " + args.object);
}

View File

@@ -0,0 +1,9 @@
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded">
<Repeater id="repeater" items="{{ items }}">
<Repeater.itemTemplate>
<GridLayout width="94" height="94" >
<Label text="{{ text }}" tap="{{ tapItem }}" />
</GridLayout>
</Repeater.itemTemplate>
</Repeater>
</Page>