Merge pull request #702 from hdeshev/special-props

Component builder functionality exposed to users
This commit is contained in:
Hristo Deshev
2015-09-09 14:09:46 +03:00
2 changed files with 38 additions and 16 deletions

View File

@ -1,10 +1,12 @@
//@private
declare module "ui/builder/component-builder" { 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 function setPropertyValue(instance: view.View, instanceModuleExports: Object, pageExports: Object, propertyName: string, propertyValue: string) : void;
export var specialProperties: Array<string>;
export function setSpecialPropertyValue(instance: view.View, propertyName: string, propertyValue: string): boolean;
export interface ComponentModule { export interface ComponentModule {
component: view.View; component: view.View;
exports: any; exports: any;

View File

@ -29,6 +29,16 @@ var DOCK = "dock";
var LEFT = "left"; var LEFT = "left";
var TOP = "top"; var TOP = "top";
export var specialProperties: Array<string> = [
ROW,
COL,
COL_SPAN,
ROW_SPAN,
DOCK,
LEFT,
TOP,
]
var eventHandlers = {}; var eventHandlers = {};
export function getComponentModule(elementName: string, namespace: string, attributes: Object, exports: Object): definition.ComponentModule { export function getComponentModule(elementName: string, namespace: string, attributes: Object, exports: Object): definition.ComponentModule {
@ -112,6 +122,28 @@ export function getComponentModule(elementName: string, namespace: string, attri
return componentModule; return componentModule;
} }
export function setSpecialPropertyValue(instance: view.View, propertyName: string, propertyValue: string) {
if (propertyName === ROW) {
gridLayoutModule.GridLayout.setRow(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === COL) {
gridLayoutModule.GridLayout.setColumn(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === COL_SPAN) {
gridLayoutModule.GridLayout.setColumnSpan(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === ROW_SPAN) {
gridLayoutModule.GridLayout.setRowSpan(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === LEFT) {
absoluteLayoutDef.AbsoluteLayout.setLeft(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === TOP) {
absoluteLayoutDef.AbsoluteLayout.setTop(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === DOCK) {
console.log('set dock: ' + propertyName + ' -> ' + propertyValue);
dockLayoutDef.DockLayout.setDock(instance, propertyValue);
} else {
return false;
}
return true;
}
export 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) {
// Note: instanceModule can be null if we are loading custom compnenet with no code-behind. // Note: instanceModule can be null if we are loading custom compnenet with no code-behind.
var isEventOrGesture: boolean = isKnownEventOrGesture(propertyName, instance); var isEventOrGesture: boolean = isKnownEventOrGesture(propertyName, instance);
@ -136,20 +168,8 @@ export function setPropertyValue(instance: view.View, instanceModule: Object, ex
if (types.isFunction(handler)) { if (types.isFunction(handler)) {
instance.on(propertyName, handler); instance.on(propertyName, handler);
} }
} else if (propertyName === ROW) { } else if (setSpecialPropertyValue(instance, propertyName, propertyValue)) {
gridLayoutModule.GridLayout.setRow(instance, !isNaN(+propertyValue) && +propertyValue); // Already set by setSpecialPropertyValue
} else if (propertyName === COL) {
gridLayoutModule.GridLayout.setColumn(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === COL_SPAN) {
gridLayoutModule.GridLayout.setColumnSpan(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === ROW_SPAN) {
gridLayoutModule.GridLayout.setRowSpan(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === LEFT) {
absoluteLayoutDef.AbsoluteLayout.setLeft(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === TOP) {
absoluteLayoutDef.AbsoluteLayout.setTop(instance, !isNaN(+propertyValue) && +propertyValue);
} else if (propertyName === DOCK) {
dockLayoutDef.DockLayout.setDock(instance, propertyValue);
} else { } else {
var attrHandled = false; var attrHandled = false;
@ -211,4 +231,4 @@ function isBinding(value: string): boolean {
} }
return isBinding; return isBinding;
} }