mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Fixed: getViewById, TextDecoration
This commit is contained in:
@@ -50,6 +50,47 @@ export function isEventOrGesture(name: string, view: ViewBaseDefinition): boolea
|
||||
return false;
|
||||
}
|
||||
|
||||
export function getViewById(view: ViewBaseDefinition, id: string): ViewBaseDefinition {
|
||||
if (!view) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (view.id === id) {
|
||||
return view;
|
||||
}
|
||||
|
||||
let retVal: ViewBaseDefinition;
|
||||
const descendantsCallback = function (child: ViewBaseDefinition): boolean {
|
||||
if (child.id === id) {
|
||||
retVal = child;
|
||||
// break the iteration by returning false
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
eachDescendant(view, descendantsCallback);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
export function eachDescendant(view: ViewBaseDefinition, callback: (child: ViewBaseDefinition) => boolean) {
|
||||
if (!callback || !view) {
|
||||
return;
|
||||
}
|
||||
|
||||
let continueIteration: boolean;
|
||||
let localCallback = function (child: ViewBaseDefinition): boolean {
|
||||
continueIteration = callback(child);
|
||||
if (continueIteration) {
|
||||
child.eachChild(localCallback);
|
||||
}
|
||||
return continueIteration;
|
||||
}
|
||||
|
||||
view.eachChild(localCallback);
|
||||
}
|
||||
|
||||
export class ViewBase extends Observable implements ViewBaseDefinition {
|
||||
private _updatingJSPropertiesDict = {};
|
||||
private _style: Style;
|
||||
@@ -87,6 +128,10 @@ export class ViewBase extends Observable implements ViewBaseDefinition {
|
||||
return this._isLoaded;
|
||||
}
|
||||
|
||||
getViewById<T extends ViewBaseDefinition>(id: string): T {
|
||||
return <T>getViewById(this, id);
|
||||
}
|
||||
|
||||
get page(): ViewBaseDefinition {
|
||||
if (this.parent) {
|
||||
return this.parent.page;
|
||||
@@ -492,4 +537,15 @@ function resetStyles(view: ViewBase): void {
|
||||
}
|
||||
|
||||
export const idProperty = new Property<ViewBase, string>({ name: "id", valueChanged: (view, oldValue, newValue) => resetStyles(view) });
|
||||
idProperty.register(ViewBase);
|
||||
idProperty.register(ViewBase);
|
||||
|
||||
export function makeValidator<T>(...values: T[]): (value: any) => value is T {
|
||||
const set = new Set(values);
|
||||
return (value: any): value is T => set.has(value);
|
||||
}
|
||||
export function makeParser<T>(isValid: (value: any) => boolean, def: T): (value: any) => T {
|
||||
return value => {
|
||||
const lower = value && value.toLowerCase();
|
||||
return isValid(lower) ? lower : def;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,47 +49,6 @@ Style.prototype.effectiveBorderRightWidth = 0;
|
||||
Style.prototype.effectiveBorderBottomWidth = 0;
|
||||
Style.prototype.effectiveBorderLeftWidth = 0;
|
||||
|
||||
export function getViewById(view: ViewDefinition, id: string): ViewDefinition {
|
||||
if (!view) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (view.id === id) {
|
||||
return view;
|
||||
}
|
||||
|
||||
let retVal: ViewDefinition;
|
||||
const descendantsCallback = function (child: ViewDefinition): boolean {
|
||||
if (child.id === id) {
|
||||
retVal = child;
|
||||
// break the iteration by returning false
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
eachDescendant(view, descendantsCallback);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
export function eachDescendant(view: ViewDefinition, callback: (child: ViewDefinition) => boolean) {
|
||||
if (!callback || !view) {
|
||||
return;
|
||||
}
|
||||
|
||||
let continueIteration: boolean;
|
||||
let localCallback = function (child: ViewDefinition): boolean {
|
||||
continueIteration = callback(child);
|
||||
if (continueIteration) {
|
||||
child._eachChildView(localCallback);
|
||||
}
|
||||
return continueIteration;
|
||||
}
|
||||
|
||||
view._eachChildView(localCallback);
|
||||
}
|
||||
|
||||
export function PseudoClassHandler(...pseudoClasses: string[]): MethodDecorator {
|
||||
let stateEventNames = pseudoClasses.map(s => ":" + s);
|
||||
let listeners = Symbol("listeners");
|
||||
@@ -233,10 +192,6 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
getViewById<T extends ViewDefinition>(id: string): T {
|
||||
return <T>getViewById(this, id);
|
||||
}
|
||||
|
||||
// START Style property shortcuts
|
||||
get borderColor(): string | Color {
|
||||
return this.style.borderColor;
|
||||
|
||||
23
tns-core-modules/ui/core/view.d.ts
vendored
23
tns-core-modules/ui/core/view.d.ts
vendored
@@ -41,14 +41,6 @@ declare module "ui/core/view" {
|
||||
export const zeroLength: Length;
|
||||
export function getLengthEffectiveValue(param: Length): number;
|
||||
|
||||
/**
|
||||
* Gets a child view by id.
|
||||
* @param view - The parent (container) view of the view to look for.
|
||||
* @param id - The id of the view to look for.
|
||||
* Returns an instance of a view (if found), otherwise undefined.
|
||||
*/
|
||||
export function getViewById(view: View, id: string): View;
|
||||
|
||||
/**
|
||||
* Converts string into boolean value.
|
||||
* Throws error if value is not 'true' or 'false'.
|
||||
@@ -350,16 +342,6 @@ declare module "ui/core/view" {
|
||||
*/
|
||||
isUserInteractionEnabled: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets the id for this view.
|
||||
*/
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the CSS class name for this view.
|
||||
*/
|
||||
className: string;
|
||||
|
||||
/**
|
||||
* Gets is layout is valid. This is a read-only property.
|
||||
*/
|
||||
@@ -475,11 +457,6 @@ declare module "ui/core/view" {
|
||||
|
||||
public static combineMeasuredStates(curState: number, newState): number;
|
||||
|
||||
/**
|
||||
* Returns the child view with the specified id.
|
||||
*/
|
||||
public getViewById<T extends View>(id: string): T;
|
||||
|
||||
/**
|
||||
* Tries to focus the view.
|
||||
* Returns a value indicating whether this view or one of its descendants actually took focus.
|
||||
|
||||
Reference in New Issue
Block a user