feat:add view tag and findViewByTag

This commit is contained in:
刘涛
2020-07-04 10:04:40 +08:00
committed by osborn
parent 42a8eb4069
commit f693719974
9 changed files with 131 additions and 16 deletions

View File

@@ -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;

View File

@@ -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;