feat:add view tag and findViewByTag
This commit is contained in:
4
doric-js/lib/src/ui/view.d.ts
vendored
4
doric-js/lib/src/ui/view.d.ts
vendored
@@ -41,6 +41,7 @@ export declare abstract class View implements Modeling {
|
||||
alpha?: number;
|
||||
hidden?: boolean;
|
||||
viewId: string;
|
||||
tag?: string;
|
||||
padding?: {
|
||||
left?: number;
|
||||
right?: number;
|
||||
@@ -53,6 +54,7 @@ export declare abstract class View implements Modeling {
|
||||
callbacks: Map<String, Function>;
|
||||
private callback2Id;
|
||||
private id2Callback;
|
||||
findViewByTag(tag: string): View | undefined;
|
||||
constructor();
|
||||
/** Anchor start*/
|
||||
get left(): number;
|
||||
@@ -130,6 +132,8 @@ export declare abstract class View implements Modeling {
|
||||
}
|
||||
export declare abstract class Superview extends View {
|
||||
subviewById(id: string): View | undefined;
|
||||
findViewByTag(tag: string): View | undefined;
|
||||
private findViewTraversal;
|
||||
abstract allSubviews(): Iterable<View>;
|
||||
isDirty(): boolean;
|
||||
clean(): void;
|
||||
|
@@ -54,6 +54,12 @@ export class View {
|
||||
}
|
||||
return f;
|
||||
}
|
||||
findViewByTag(tag) {
|
||||
if (tag === this.tag) {
|
||||
return this;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/** Anchor start*/
|
||||
get left() {
|
||||
return this.x;
|
||||
@@ -290,6 +296,21 @@ export class Superview extends View {
|
||||
}
|
||||
}
|
||||
}
|
||||
findViewByTag(tag) {
|
||||
if (tag === this.tag) {
|
||||
return this;
|
||||
}
|
||||
return this.findViewTraversal(this, tag);
|
||||
}
|
||||
findViewTraversal(view, tag) {
|
||||
for (let v of view.allSubviews()) {
|
||||
let find = v.findViewByTag(tag);
|
||||
if (find) {
|
||||
return find;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
isDirty() {
|
||||
if (super.isDirty()) {
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user