mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Fixed issue with binding gestures to repeater items.
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user