From 4dcc89497dd066ef4960e846a5af6cb89e622dc1 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Wed, 13 Nov 2019 20:43:05 +0800 Subject: [PATCH] listview enable cell refresh --- .../main/java/pub/doric/shader/GroupNode.java | 13 ++++++++ .../main/java/pub/doric/shader/SuperNode.java | 16 ++++++++++ .../pub/doric/shader/list/ListAdapter.java | 21 ++++++++++++- .../java/pub/doric/shader/list/ListNode.java | 5 ++++ demo/src/ListDemo.ts | 2 ++ js-framework/src/ui/listview.ts | 4 --- js-framework/src/ui/view.ts | 30 ++++++++++++------- 7 files changed, 75 insertions(+), 16 deletions(-) diff --git a/Android/doric/src/main/java/pub/doric/shader/GroupNode.java b/Android/doric/src/main/java/pub/doric/shader/GroupNode.java index ac6d3afe..ecc16392 100644 --- a/Android/doric/src/main/java/pub/doric/shader/GroupNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/GroupNode.java @@ -105,8 +105,21 @@ public abstract class GroupNode extends SuperNode { for (ViewNode node : tobeRemoved) { mChildrenNode.remove(node.getId()); } + } else if ("subviews".equals(name)) { + // Currently do nothing,because its subview always contained in props.children + // super.blend(view, layoutParams, name, prop); } else { super.blend(view, layoutParams, name, prop); } } + + @Override + protected void blendSubNode(JSObject subProp) { + String subNodeId = subProp.getProperty("id").asString().value(); + for (ViewNode node : mChildrenNode.values()) { + if (subNodeId.equals(node.getId())) { + node.blend(subProp, node.getLayoutParams()); + } + } + } } diff --git a/Android/doric/src/main/java/pub/doric/shader/SuperNode.java b/Android/doric/src/main/java/pub/doric/shader/SuperNode.java index f2d003b0..eaa8d790 100644 --- a/Android/doric/src/main/java/pub/doric/shader/SuperNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/SuperNode.java @@ -18,6 +18,7 @@ package pub.doric.shader; import android.view.View; import android.view.ViewGroup; +import com.github.pengfeizhou.jscore.JSArray; import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSValue; @@ -38,6 +39,21 @@ public abstract class SuperNode extends ViewNode { return new ViewGroup.LayoutParams(0, 0); } + @Override + protected void blend(V view, ViewGroup.LayoutParams layoutParams, String name, JSValue prop) { + if (name.equals("subviews")) { + JSArray subviews = prop.asArray(); + for (int i = 0; i < subviews.size(); i++) { + JSObject subProp = subviews.get(i).asObject(); + blendSubNode(subProp); + } + } else { + super.blend(view, layoutParams, name, prop); + } + } + + protected abstract void blendSubNode(JSObject subProperties); + protected void blendSubLayoutConfig(ViewNode viewNode, JSObject jsObject) { JSValue jsValue = jsObject.getProperty("margin"); JSValue widthSpec = jsObject.getProperty("widthSpec"); diff --git a/Android/doric/src/main/java/pub/doric/shader/list/ListAdapter.java b/Android/doric/src/main/java/pub/doric/shader/list/ListAdapter.java index 54dfd9ac..e20f6f86 100644 --- a/Android/doric/src/main/java/pub/doric/shader/list/ListAdapter.java +++ b/Android/doric/src/main/java/pub/doric/shader/list/ListAdapter.java @@ -26,6 +26,9 @@ import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSValue; +import java.util.HashMap; +import java.util.Map; + import pub.doric.async.AsyncResult; import pub.doric.shader.ViewNode; @@ -58,7 +61,7 @@ public class ListAdapter extends RecyclerView.Adapter { this.listAdapter = new ListAdapter(this); } + @Override + protected void blendSubNode(JSObject subProperties) { + listAdapter.blendSubNode(subProperties); + } + @Override protected RecyclerView build(JSObject jsObject) { RecyclerView recyclerView = new RecyclerView(getContext()); diff --git a/demo/src/ListDemo.ts b/demo/src/ListDemo.ts index a1bd8300..fafa42cf 100644 --- a/demo/src/ListDemo.ts +++ b/demo/src/ListDemo.ts @@ -43,6 +43,8 @@ class ListPanel extends Panel { it.height = 50 it.onClick = () => { log(`Click item at ${idx}`) + it.bgColor = Color.parse('#000000') + log(`changed,listview is dirty:${list.isDirty()}`) } }) } diff --git a/js-framework/src/ui/listview.ts b/js-framework/src/ui/listview.ts index 1ea2d0c1..41c35fb3 100644 --- a/js-framework/src/ui/listview.ts +++ b/js-framework/src/ui/listview.ts @@ -40,10 +40,6 @@ export class ListItem extends Stack { export class List extends Superview { private cachedViews: Map = new Map - subviewById(id: string): ListItem | undefined { - return this.cachedViews.get(id) - } - allSubviews() { return this.cachedViews.values() } diff --git a/js-framework/src/ui/view.ts b/js-framework/src/ui/view.ts index 53b244f8..0527eb5a 100644 --- a/js-framework/src/ui/view.ts +++ b/js-framework/src/ui/view.ts @@ -256,7 +256,13 @@ export abstract class View implements Modeling, IView { } export abstract class Superview extends View { - abstract subviewById(id: string): View | undefined + subviewById(id: string): View | undefined { + for (let v of this.allSubviews()) { + if (v.viewId === id) { + return v + } + } + } abstract allSubviews(): Iterable isDirty() { @@ -271,6 +277,17 @@ export abstract class Superview extends View { } return false } + + toModel() { + const subviews = [] + for (let v of this.allSubviews()) { + if (v.isDirty()) { + subviews.push(v.toModel()) + } + } + this.dirtyProps.subviews = subviews + return super.toModel() + } } export abstract class Group extends Superview { @@ -284,15 +301,6 @@ export abstract class Group extends Superview { } }) - subviewById(id: string): View | undefined { - for (let view of this.children) { - if (view.viewId === id) { - return view - } - } - return undefined - } - allSubviews() { return this.children } @@ -310,7 +318,7 @@ export abstract class Group extends Superview { return {} } }) - return super.toModel() + return this.nativeViewModel } }