From eea7eb5d27ebf8031d14d172b4b1996d4fd2615c Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 12 Nov 2019 17:59:38 +0800 Subject: [PATCH] feat:refact View Dirty Props,prepare to use in ListView --- demo/src/Counter.ts | 8 ++++++-- js-framework/src/ui/listview.ts | 4 ++++ js-framework/src/ui/panel.ts | 4 ++-- js-framework/src/ui/view.ts | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/demo/src/Counter.ts b/demo/src/Counter.ts index 68267b11..d87724c6 100644 --- a/demo/src/Counter.ts +++ b/demo/src/Counter.ts @@ -13,7 +13,9 @@ class CounterView extends ViewHolder { 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 { }, corners: 5, layoutConfig: { - alignment: new Gravity().center() + alignment: new Gravity().center(), + widthSpec: LayoutSpec.WRAP_CONTENT, + heightSpec: LayoutSpec.WRAP_CONTENT, }, shadow: { color: Color.parse("#00ff00"), diff --git a/js-framework/src/ui/listview.ts b/js-framework/src/ui/listview.ts index cfc1f48a..ad0b3f0e 100644 --- a/js-framework/src/ui/listview.ts +++ b/js-framework/src/ui/listview.ts @@ -44,6 +44,10 @@ export class List extends Superview { return this.cachedViews.get(id) } + allSubviews() { + return this.cachedViews.values() + } + @Property itemCount = 0 diff --git a/js-framework/src/ui/panel.ts b/js-framework/src/ui/panel.ts index 0aae8d94..245e1454 100644 --- a/js-framework/src/ui/panel.ts +++ b/js-framework/src/ui/panel.ts @@ -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__) diff --git a/js-framework/src/ui/view.ts b/js-framework/src/ui/view.ts index 5be2291f..b955a3f6 100644 --- a/js-framework/src/ui/view.ts +++ b/js-framework/src/ui/view.ts @@ -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 + + 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) }