feat:add view tag and findViewByTag
This commit is contained in:
@@ -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() {
|
||||
|
Reference in New Issue
Block a user