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

@@ -69,6 +69,8 @@ export abstract class View implements Modeling {
viewId = uniqueId('ViewId')
tag?: string
@Property
padding?: {
left?: number,
@@ -101,6 +103,13 @@ export abstract class View implements Modeling {
return f
}
findViewByTag(tag: string): View | undefined {
if (tag === this.tag) {
return this;
}
return undefined;
}
constructor() {
return new Proxy(this, {
get: (target, p, receiver) => {
@@ -343,6 +352,23 @@ export abstract class Superview extends View {
}
}
}
findViewByTag(tag: string): View | undefined {
if (tag === this.tag) {
return this
}
return this.findViewTraversal(this, tag)
}
private findViewTraversal(view: Superview, tag: string): View | undefined {
for (let v of view.allSubviews()) {
let find = v.findViewByTag(tag);
if (find) {
return find;
}
}
return undefined;
}
abstract allSubviews(): Iterable<View>
isDirty() {