mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
Merge pull request #702 from hdeshev/special-props
Component builder functionality exposed to users
This commit is contained in:
4
ui/builder/component-builder.d.ts
vendored
4
ui/builder/component-builder.d.ts
vendored
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user