mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Fixed issue with binding gestures to repeater items.
This commit is contained in:
@ -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" />
|
||||
@ -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" />
|
||||
|
@ -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();
|
||||
|
14
apps/tests/ui/repeaterItems-bindingToGestures.ts
Normal file
14
apps/tests/ui/repeaterItems-bindingToGestures.ts
Normal 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);
|
||||
}
|
9
apps/tests/ui/repeaterItems-bindingToGestures.xml
Normal file
9
apps/tests/ui/repeaterItems-bindingToGestures.xml
Normal 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>
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user