mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 05:18:39 +08:00
properties will be copied to the custom component with XML + tests
This commit is contained in:
@ -10,6 +10,9 @@ import types = require("utils/types");
|
|||||||
import fs = require("file-system");
|
import fs = require("file-system");
|
||||||
import fileSystemAccess = require("file-system/file-system-access");
|
import fileSystemAccess = require("file-system/file-system-access");
|
||||||
import observable = require("data/observable");
|
import observable = require("data/observable");
|
||||||
|
import stackLayoutModule = require("ui/layouts/stack-layout");
|
||||||
|
import labelModule = require("ui/label");
|
||||||
|
import myCustomControlWithoutXml = require("./mymodule/MyControl");
|
||||||
|
|
||||||
export var test_load_IsDefined = function () {
|
export var test_load_IsDefined = function () {
|
||||||
TKUnit.assert(types.isFunction(builder.load), "ui/builder should have load method!");
|
TKUnit.assert(types.isFunction(builder.load), "ui/builder should have load method!");
|
||||||
@ -154,3 +157,25 @@ export var test_parse_ShouldParseSubProperties = function () {
|
|||||||
|
|
||||||
TKUnit.assert(sw.visibility === "collapsed", "Expected result: collapsed; Actual result: " + sw.visibility + "; type: " + typeof (sw.visibility));
|
TKUnit.assert(sw.visibility === "collapsed", "Expected result: collapsed; Actual result: " + sw.visibility + "; type: " + typeof (sw.visibility));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export var test_parse_ShouldParseCustomComponentWithoutXml = function () {
|
||||||
|
var p = <page.Page>builder.parse('<Page xmlns:customControls="xml-declaration/mymodule"><customControls:MyControl /></Page>');
|
||||||
|
var ctrl = p.content;
|
||||||
|
|
||||||
|
TKUnit.assert(ctrl instanceof myCustomControlWithoutXml.MyControl, "Expected result: custom control is defined!; Actual result: " + ctrl);
|
||||||
|
};
|
||||||
|
|
||||||
|
export var test_parse_ShouldParseCustomComponentWitXml = function () {
|
||||||
|
var p = <page.Page>builder.parse('<Page xmlns:customControls="xml-declaration/mymodulewithxml"><customControls:MyControl /></Page>');
|
||||||
|
var panel = <stackLayoutModule.StackLayout>p.content;
|
||||||
|
var lbl = <labelModule.Label>panel.getChildAt(0);
|
||||||
|
|
||||||
|
TKUnit.assert(lbl.text === "mymodulewithxml", "Expected result: 'mymodulewithxml'; Actual result: " + lbl);
|
||||||
|
};
|
||||||
|
|
||||||
|
export var test_parse_ShouldParseCustomComponentWitXmlWithAttributes = function () {
|
||||||
|
var p = <page.Page>builder.parse('<Page xmlns:customControls="xml-declaration/mymodulewithxml"><customControls:MyControl visibility="collapsed" /></Page>');
|
||||||
|
var panel = <stackLayoutModule.StackLayout>p.content;
|
||||||
|
|
||||||
|
TKUnit.assert(panel.visibility === "collapsed", "Expected result: 'collapsed'; Actual result: " + panel.visibility);
|
||||||
|
};
|
||||||
|
@ -83,8 +83,17 @@ function parseInternal(value: string, exports: any): componentBuilder.ComponentM
|
|||||||
// Custom components with XML and code
|
// Custom components with XML and code
|
||||||
subExports = require(jsPath.replace(".js", ""))
|
subExports = require(jsPath.replace(".js", ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
componentModule = loadInternal(xmlPath, subExports);
|
componentModule = loadInternal(xmlPath, subExports);
|
||||||
|
|
||||||
|
// Attributes will be transfered to the custom component
|
||||||
|
if (types.isDefined(componentModule) && types.isDefined(componentModule.component)) {
|
||||||
|
var attr: string;
|
||||||
|
for (attr in args.attributes) {
|
||||||
|
componentBuilder.setPropertyValue(componentModule.component, subExports, exports, attr, args.attributes[attr]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Custom components without XML
|
// Custom components without XML
|
||||||
componentModule = componentBuilder.getComponentModule(args.elementName, args.namespace, args.attributes, exports);
|
componentModule = componentBuilder.getComponentModule(args.elementName, args.namespace, args.attributes, exports);
|
||||||
|
1
ui/builder/component-builder.d.ts
vendored
1
ui/builder/component-builder.d.ts
vendored
@ -3,6 +3,7 @@ declare module "ui/builder/component-builder" {
|
|||||||
import view = require("ui/core/view");
|
import view = require("ui/core/view");
|
||||||
|
|
||||||
export function getComponentModule(elementName: string, namespace: string, attributes: Object, exports: Object): ComponentModule;
|
export function getComponentModule(elementName: string, namespace: string, attributes: Object, exports: Object): ComponentModule;
|
||||||
|
export function setPropertyValue(instance: view.View, instanceModuleExports: Object, pageExports: Object, propertyName: string, propertyValue: string) : void;
|
||||||
|
|
||||||
export interface ComponentModule {
|
export interface ComponentModule {
|
||||||
component: view.View;
|
component: view.View;
|
||||||
|
@ -102,7 +102,7 @@ export function getComponentModule(elementName: string, namespace: string, attri
|
|||||||
return componentModule;
|
return componentModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setPropertyValue(instance: view.View, instanceModule: Object, exports: Object, propertyName: string, propertyValue: string) {
|
export function setPropertyValue(instance: view.View, instanceModule: Object, exports: Object, propertyName: string, propertyValue: string) {
|
||||||
if (isBinding(propertyValue) && instance.bind) {
|
if (isBinding(propertyValue) && instance.bind) {
|
||||||
if (isKnownEvent(propertyName, instanceModule)) {
|
if (isKnownEvent(propertyName, instanceModule)) {
|
||||||
attachEventBinding(instance, propertyName, propertyValue);
|
attachEventBinding(instance, propertyName, propertyValue);
|
||||||
|
Reference in New Issue
Block a user