Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CrossPlatformModules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
<TypeScriptCompile Include="apps\tests\ui\search-bar\search-bar-tests-native.android.ts" />
<TypeScriptCompile Include="apps\tests\ui\search-bar\search-bar-tests-native.d.ts" />
<TypeScriptCompile Include="apps\tests\ui\search-bar\search-bar-tests-native.ios.ts" />
<TypeScriptCompile Include="apps\tests\ui\repeaterItems-bindingToGestures.ts" />
<TypeScriptCompile Include="apps\tests\xml-declaration\inherited-base-page.ts" />
<TypeScriptCompile Include="apps\tests\xml-declaration\inherited-page.ts" />
<TypeScriptCompile Include="apps\ui-tests-app\pages\handlers.ts" />
Expand Down Expand Up @@ -898,6 +899,7 @@
<Content Include="apps\tests\pages\page18.xml" />
<Content Include="apps\tests\pages\test2.png" />
<Content Include="apps\tests\ui\bindingContext_testPage.xml" />
<Content Include="apps\tests\ui\repeaterItems-bindingToGestures.xml" />
<Content Include="apps\tests\ui\test-pages\bindingExpressions_logicalComparisonOperators_testPage.xml" />
<Content Include="apps\tests\ui\test-pages\bindingExpressions_comparisonOperators_testPage.xml" />
<Content Include="apps\tests\ui\test-pages\bindingExpressions_binaryOperators_testPage.xml" />
Expand Down
27 changes: 27 additions & 0 deletions apps/tests/ui/bindable-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions apps/tests/ui/repeaterItems-bindingToGestures.ts
Original file line number Diff line number Diff line change
@@ -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);
}
9 changes: 9 additions & 0 deletions apps/tests/ui/repeaterItems-bindingToGestures.xml
Original file line number Diff line number Diff line change
@@ -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>
2 changes: 1 addition & 1 deletion ui/repeater/repeater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ export class Repeater extends viewModule.CustomLayoutView implements definition.
for (i = 0; i < this.items.length; i++) {
var viewToAdd = !types.isNullOrUndefined(this.itemTemplate) ? builder.parse(this.itemTemplate, this) : this._getDefaultItemContent(i);
if (!types.isNullOrUndefined(viewToAdd)) {
this.itemsLayout.addChild(viewToAdd);
viewToAdd.bindingContext = this._getDataItem(i);
this.itemsLayout.addChild(viewToAdd);
}
}
}
Expand Down