listview enable cell refresh
This commit is contained in:
parent
3933582e1e
commit
4dcc89497d
@ -105,8 +105,21 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<V extends View> extends ViewNode<V> {
|
||||
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");
|
||||
|
@ -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<ListAdapter.DoricViewHolde
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DoricViewHolder holder, int position) {
|
||||
JSObject jsObject = getItemModel(position);
|
||||
holder.listItemNode.setId(String.valueOf(position));
|
||||
holder.listItemNode.setId(jsObject.getProperty("id").asString().value());
|
||||
holder.listItemNode.blend(jsObject.getProperty("props").asObject(), holder.itemView.getLayoutParams());
|
||||
}
|
||||
|
||||
@ -101,6 +104,22 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.DoricViewHolde
|
||||
}
|
||||
|
||||
|
||||
public void blendSubNode(JSObject subProperties) {
|
||||
String subNodeId = subProperties.getProperty("id").asString().value();
|
||||
for (int i = 0; i < itemObjects.size(); i++) {
|
||||
JSObject jsObject = itemObjects.valueAt(i);
|
||||
if (subNodeId.equals(jsObject.getProperty("id").asString().value())) {
|
||||
for (String key : subProperties.propertySet()) {
|
||||
jsObject.setProperty(key, subProperties.getProperty(key));
|
||||
}
|
||||
int position = itemObjects.keyAt(i);
|
||||
notifyItemChanged(position);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class DoricViewHolder extends RecyclerView.ViewHolder {
|
||||
ListItemNode listItemNode;
|
||||
|
||||
|
@ -42,6 +42,11 @@ public class ListNode extends SuperNode<RecyclerView> {
|
||||
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());
|
||||
|
@ -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()}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -40,10 +40,6 @@ export class ListItem extends Stack {
|
||||
export class List extends Superview {
|
||||
private cachedViews: Map<string, ListItem> = new Map
|
||||
|
||||
subviewById(id: string): ListItem | undefined {
|
||||
return this.cachedViews.get(id)
|
||||
}
|
||||
|
||||
allSubviews() {
|
||||
return this.cachedViews.values()
|
||||
}
|
||||
|
@ -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<View>
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user