feat:remove JSObject while build in node

This commit is contained in:
pengfei.zhou 2019-11-14 18:04:53 +08:00
parent d2f4302e42
commit 9e505894b0
9 changed files with 22 additions and 13 deletions

View File

@ -34,8 +34,8 @@ public class HLayoutNode extends LinearNode {
} }
@Override @Override
protected LinearLayout build(JSObject jsObject) { protected LinearLayout build() {
LinearLayout linearLayout = super.build(jsObject); LinearLayout linearLayout = super.build();
linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setOrientation(LinearLayout.HORIZONTAL);
return linearLayout; return linearLayout;
} }

View File

@ -46,7 +46,7 @@ public class ImageNode extends ViewNode<ImageView> {
} }
@Override @Override
protected ImageView build(JSObject jsObject) { protected ImageView build() {
return new ImageView(getContext()); return new ImageView(getContext());
} }

View File

@ -54,7 +54,7 @@ public class LinearNode extends GroupNode<LinearLayout> {
} }
@Override @Override
protected LinearLayout build(JSObject jsObject) { protected LinearLayout build() {
return new LinearLayout(getContext()); return new LinearLayout(getContext());
} }

View File

@ -45,7 +45,7 @@ public class StackNode extends GroupNode<FrameLayout> {
} }
@Override @Override
protected FrameLayout build(JSObject jsObject) { protected FrameLayout build() {
return new FrameLayout(getContext()); return new FrameLayout(getContext());
} }

View File

@ -37,7 +37,7 @@ public class TextNode extends ViewNode<TextView> {
} }
@Override @Override
protected TextView build(JSObject jsObject) { protected TextView build() {
return new TextView(getContext()); return new TextView(getContext());
} }

View File

@ -34,8 +34,8 @@ public class VLayoutNode extends LinearNode {
} }
@Override @Override
protected LinearLayout build(JSObject jsObject) { protected LinearLayout build() {
LinearLayout linearLayout = super.build(jsObject); LinearLayout linearLayout = super.build();
linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setOrientation(LinearLayout.VERTICAL);
return linearLayout; return linearLayout;
} }

View File

@ -41,7 +41,6 @@ import java.util.LinkedList;
*/ */
public abstract class ViewNode<T extends View> extends DoricContextHolder { public abstract class ViewNode<T extends View> extends DoricContextHolder {
protected T mView; protected T mView;
int index;
SuperNode mSuperNode; SuperNode mSuperNode;
String mId; String mId;
private ViewGroup.LayoutParams mLayoutParams; private ViewGroup.LayoutParams mLayoutParams;
@ -52,6 +51,16 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
private DoricLayer doricLayer; private DoricLayer doricLayer;
public void init(SuperNode superNode) {
this.mSuperNode = superNode;
this.mLayoutParams = superNode.generateDefaultLayoutParams();
this.doricLayer = new DoricLayer(getContext());
this.mView = build();
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(mLayoutParams.width, mLayoutParams.height);
doricLayer.addView(mView, params);
}
public void setSuperNode(SuperNode parentNode) { public void setSuperNode(SuperNode parentNode) {
mSuperNode = parentNode; mSuperNode = parentNode;
} }
@ -68,12 +77,12 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
return getDoricContext().getContext(); return getDoricContext().getContext();
} }
protected abstract T build(JSObject jsObject); protected abstract T build();
public void blend(JSObject jsObject, ViewGroup.LayoutParams layoutParams) { public void blend(JSObject jsObject, ViewGroup.LayoutParams layoutParams) {
mLayoutParams = layoutParams; mLayoutParams = layoutParams;
if (mView == null) { if (mView == null) {
mView = build(jsObject); mView = build();
} }
if (getDoricLayer() == null) { if (getDoricLayer() == null) {
doricLayer = new DoricLayer(getContext()); doricLayer = new DoricLayer(getContext());

View File

@ -35,7 +35,7 @@ public class ListItemNode extends StackNode {
public ListItemNode(DoricContext doricContext) { public ListItemNode(DoricContext doricContext) {
super(doricContext); super(doricContext);
this.mView = this.build(null); this.mView = this.build();
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT); ViewGroup.LayoutParams.WRAP_CONTENT);
this.blend(null, params); this.blend(null, params);

View File

@ -48,7 +48,7 @@ public class ListNode extends SuperNode<RecyclerView> {
} }
@Override @Override
protected RecyclerView build(JSObject jsObject) { protected RecyclerView build() {
RecyclerView recyclerView = new RecyclerView(getContext()); RecyclerView recyclerView = new RecyclerView(getContext());
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(this.listAdapter); recyclerView.setAdapter(this.listAdapter);