feat:add reusable in GroupNode for Android
This commit is contained in:
parent
8e53e4b54b
commit
e4b729b2fd
@ -34,6 +34,8 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
|
||||
private ArrayList<ViewNode> mChildNodes = new ArrayList<>();
|
||||
private ArrayList<String> mChildViewIds = new ArrayList<>();
|
||||
|
||||
protected boolean mReusable = false;
|
||||
|
||||
public GroupNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
@ -66,6 +68,26 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
|
||||
ViewNode oldNode = mChildNodes.get(idx);
|
||||
if (id.equals(oldNode.getId())) {
|
||||
//The same,skip
|
||||
} else {
|
||||
if (mReusable) {
|
||||
if (oldNode.getType().equals(type)) {
|
||||
//Same type,can be reused
|
||||
oldNode.setId(id);
|
||||
oldNode.blend(model.getProperty("props").asObject());
|
||||
} else {
|
||||
//Replace this view
|
||||
mChildNodes.remove(idx);
|
||||
mView.removeView(oldNode.getDoricLayer());
|
||||
ViewNode newNode = ViewNode.create(getDoricContext(), type);
|
||||
newNode.setId(id);
|
||||
if (newNode instanceof GroupNode) {
|
||||
((GroupNode) newNode).mReusable = this.mReusable;
|
||||
}
|
||||
newNode.init(this);
|
||||
newNode.blend(model.getProperty("props").asObject());
|
||||
mChildNodes.add(idx, newNode);
|
||||
mView.addView(newNode.getDoricLayer(), idx, newNode.getLayoutParams());
|
||||
}
|
||||
} else {
|
||||
//Find in remain nodes
|
||||
int position = -1;
|
||||
@ -99,10 +121,14 @@ public abstract class GroupNode<F extends ViewGroup> extends SuperNode<F> {
|
||||
mView.addView(newNode.getDoricLayer(), idx, newNode.getLayoutParams());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//Insert
|
||||
ViewNode newNode = ViewNode.create(getDoricContext(), type);
|
||||
newNode.setId(id);
|
||||
if (newNode instanceof GroupNode) {
|
||||
((GroupNode) newNode).mReusable = this.mReusable;
|
||||
}
|
||||
newNode.init(this);
|
||||
newNode.blend(model.getProperty("props").asObject());
|
||||
mChildNodes.add(newNode);
|
||||
|
@ -44,6 +44,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
SuperNode mSuperNode;
|
||||
String mId;
|
||||
protected ViewGroup.LayoutParams mLayoutParams;
|
||||
private String mType;
|
||||
|
||||
public ViewNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
@ -65,6 +66,10 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
this.mId = id;
|
||||
}
|
||||
|
||||
public String getType(){
|
||||
return mType;
|
||||
}
|
||||
|
||||
public View getDoricLayer() {
|
||||
return doricLayer;
|
||||
}
|
||||
@ -199,7 +204,9 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
public static ViewNode create(DoricContext doricContext, String type) {
|
||||
DoricRegistry registry = doricContext.getDriver().getRegistry();
|
||||
DoricMetaInfo<ViewNode> clz = registry.acquireViewNodeInfo(type);
|
||||
return clz.createInstance(doricContext);
|
||||
ViewNode ret = clz.createInstance(doricContext);
|
||||
ret.mType = type;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public ViewGroup.LayoutParams getLayoutParams() {
|
||||
|
@ -34,6 +34,7 @@ public class ListItemNode extends StackNode {
|
||||
|
||||
public ListItemNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
this.mReusable = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user