mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
Expose configurable attributes property when loading components
This commit is contained in:
1
ui/builder/builder.d.ts
vendored
1
ui/builder/builder.d.ts
vendored
@ -9,6 +9,7 @@
|
||||
export interface LoadOptions {
|
||||
path: string;
|
||||
name: string;
|
||||
attributes?: any;
|
||||
exports?: any;
|
||||
page?: page.Page;
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ export function load(pathOrOptions: string | LoadOptions, context?: any): View {
|
||||
if (!context) {
|
||||
if (!isString(pathOrOptions)) {
|
||||
let options = <LoadOptions>pathOrOptions;
|
||||
componentModule = loadCustomComponent(options.path, options.name, undefined, options.exports, options.page);
|
||||
componentModule = loadCustomComponent(options.path, options.name, options.attributes, options.exports, options.page);
|
||||
} else {
|
||||
let path = <string>pathOrOptions;
|
||||
componentModule = loadInternal(path);
|
||||
|
2
ui/builder/component-builder.d.ts
vendored
2
ui/builder/component-builder.d.ts
vendored
@ -2,7 +2,7 @@ declare module "ui/builder/component-builder" {
|
||||
import view = require("ui/core/view");
|
||||
|
||||
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: any) : void;
|
||||
|
||||
export interface ComponentModule {
|
||||
component: view.View;
|
||||
|
@ -154,7 +154,7 @@ export function getComponentModule(elementName: string, namespace: string, attri
|
||||
return componentModule;
|
||||
}
|
||||
|
||||
export function setPropertyValue(instance: View, instanceModule: Object, exports: Object, propertyName: string, propertyValue: string) {
|
||||
export function setPropertyValue(instance: View, instanceModule: Object, exports: Object, propertyName: string, propertyValue: any) {
|
||||
// Note: instanceModule can be null if we are loading custom compnenet with no code-behind.
|
||||
|
||||
if (isBinding(propertyValue) && instance.bind) {
|
||||
@ -183,7 +183,7 @@ export function setPropertyValue(instance: View, instanceModule: Object, exports
|
||||
if (!attrHandled && (<any>instance)._applyXmlAttribute) {
|
||||
attrHandled = (<any>instance)._applyXmlAttribute(propertyName, propertyValue);
|
||||
}
|
||||
if (!attrHandled) {
|
||||
if (!attrHandled) {
|
||||
instance[propertyName] = convertString(propertyValue);
|
||||
}
|
||||
}
|
||||
@ -193,7 +193,7 @@ function getBindingExpressionFromAttribute(value: string): string {
|
||||
return value.replace("{{", "").replace("}}", "").trim();
|
||||
}
|
||||
|
||||
function isBinding(value: string): boolean {
|
||||
function isBinding(value: any): boolean {
|
||||
var isBinding;
|
||||
|
||||
if (isString(value)) {
|
||||
|
2
ui/builder/special-properties.d.ts
vendored
2
ui/builder/special-properties.d.ts
vendored
@ -1,7 +1,7 @@
|
||||
declare module "ui/builder/special-properties" {
|
||||
import view = require("ui/core/view");
|
||||
|
||||
export type PropertySetter = (instance: view.View, propertyValue: string) => void;
|
||||
export type PropertySetter = (instance: view.View, propertyValue: any) => void;
|
||||
export function registerSpecialProperty(name: string, setter: PropertySetter): void;
|
||||
export function getSpecialPropertySetter(name: string): PropertySetter;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import view = require("ui/core/view");
|
||||
|
||||
export type PropertySetter = (instance: view.View, propertyValue: string) => void;
|
||||
export type PropertySetter = (instance: view.View, propertyValue: any) => void;
|
||||
|
||||
var specialProperties: Map<string, PropertySetter> = new Map<string, PropertySetter>();
|
||||
|
||||
|
@ -34,10 +34,12 @@ export function escapeRegexSymbols(source: string): string {
|
||||
return source.replace(escapeRegex, "\\$&");
|
||||
}
|
||||
|
||||
export function convertString(value: string): any {
|
||||
export function convertString(value: any): any {
|
||||
var result;
|
||||
|
||||
if (value.trim() === "") {
|
||||
|
||||
if (!types.isString(value)) {
|
||||
result = value;
|
||||
} else if (value.trim() === "") {
|
||||
result = value;
|
||||
} else {
|
||||
// Try to convert value to number.
|
||||
@ -50,7 +52,7 @@ export function convertString(value: string): any {
|
||||
result = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -131,4 +133,4 @@ export function isDataURI(uri: string): boolean {
|
||||
var firstSegment = uri.trim().split(',')[0];
|
||||
|
||||
return firstSegment && firstSegment.indexOf("data:") === 0 && firstSegment.indexOf('base64') >= 0;
|
||||
}
|
||||
}
|
||||
|
2
utils/utils.d.ts
vendored
2
utils/utils.d.ts
vendored
@ -240,5 +240,5 @@
|
||||
* Converts string value to number or boolean.
|
||||
* @param value The original value.
|
||||
*/
|
||||
export function convertString(value: string): any
|
||||
export function convertString(value: any): any
|
||||
}
|
||||
|
Reference in New Issue
Block a user