feat:refact View Dirty Props,prepare to use in ListView

This commit is contained in:
pengfei.zhou 2019-11-12 17:59:38 +08:00
parent dab3c00b4c
commit eea7eb5d27
4 changed files with 30 additions and 4 deletions

View File

@ -13,7 +13,9 @@ class CounterView extends ViewHolder<CountModel> {
text({
textSize: 40,
layoutConfig: {
alignment: new Gravity().center()
alignment: new Gravity().center(),
widthSpec: LayoutSpec.WRAP_CONTENT,
heightSpec: LayoutSpec.WRAP_CONTENT,
},
}).also(it => { this.number = it }),
text({
@ -25,7 +27,9 @@ class CounterView extends ViewHolder<CountModel> {
},
corners: 5,
layoutConfig: {
alignment: new Gravity().center()
alignment: new Gravity().center(),
widthSpec: LayoutSpec.WRAP_CONTENT,
heightSpec: LayoutSpec.WRAP_CONTENT,
},
shadow: {
color: Color.parse("#00ff00"),

View File

@ -44,6 +44,10 @@ export class List extends Superview {
return this.cachedViews.get(id)
}
allSubviews() {
return this.cachedViews.values()
}
@Property
itemCount = 0

View File

@ -99,8 +99,8 @@ export abstract class Panel {
private retrospectView(ids: string[]): View {
return ids.reduce((acc: View, cur) => {
if (Reflect.has(acc, "subViewById")) {
return Reflect.apply(Reflect.get(acc, "subViewById"), acc, [cur])
if (Reflect.has(acc, "subviewById")) {
return Reflect.apply(Reflect.get(acc, "subviewById"), acc, [cur])
}
return acc
}, this.__root__)

View File

@ -254,6 +254,20 @@ export abstract class View implements Modeling, IView {
export abstract class Superview extends View {
abstract subviewById(id: string): View | undefined
abstract allSubviews(): Iterable<View>
isDirty() {
if (super.isDirty()) {
return true
} else {
for (const v of this.allSubviews()) {
if (v.isDirty()) {
return true
}
}
}
return false
}
}
export abstract class Group extends Superview {
@ -276,6 +290,10 @@ export abstract class Group extends Superview {
return undefined
}
allSubviews() {
return this.children
}
addChild(view: View) {
this.children.push(view)
}