From 9e505894b0125a1801fd0fe35643a3baadd06ea7 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Thu, 14 Nov 2019 18:04:53 +0800 Subject: [PATCH] feat:remove JSObject while build in node --- .../main/java/pub/doric/shader/HLayoutNode.java | 4 ++-- .../src/main/java/pub/doric/shader/ImageNode.java | 2 +- .../main/java/pub/doric/shader/LinearNode.java | 2 +- .../src/main/java/pub/doric/shader/StackNode.java | 2 +- .../src/main/java/pub/doric/shader/TextNode.java | 2 +- .../main/java/pub/doric/shader/VLayoutNode.java | 4 ++-- .../src/main/java/pub/doric/shader/ViewNode.java | 15 ++++++++++++--- .../java/pub/doric/shader/list/ListItemNode.java | 2 +- .../main/java/pub/doric/shader/list/ListNode.java | 2 +- 9 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Android/doric/src/main/java/pub/doric/shader/HLayoutNode.java b/Android/doric/src/main/java/pub/doric/shader/HLayoutNode.java index 9eb0719c..240158d8 100644 --- a/Android/doric/src/main/java/pub/doric/shader/HLayoutNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/HLayoutNode.java @@ -34,8 +34,8 @@ public class HLayoutNode extends LinearNode { } @Override - protected LinearLayout build(JSObject jsObject) { - LinearLayout linearLayout = super.build(jsObject); + protected LinearLayout build() { + LinearLayout linearLayout = super.build(); linearLayout.setOrientation(LinearLayout.HORIZONTAL); return linearLayout; } diff --git a/Android/doric/src/main/java/pub/doric/shader/ImageNode.java b/Android/doric/src/main/java/pub/doric/shader/ImageNode.java index bbf45925..9ce37c9c 100644 --- a/Android/doric/src/main/java/pub/doric/shader/ImageNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/ImageNode.java @@ -46,7 +46,7 @@ public class ImageNode extends ViewNode { } @Override - protected ImageView build(JSObject jsObject) { + protected ImageView build() { return new ImageView(getContext()); } diff --git a/Android/doric/src/main/java/pub/doric/shader/LinearNode.java b/Android/doric/src/main/java/pub/doric/shader/LinearNode.java index 5577d516..6278a98e 100644 --- a/Android/doric/src/main/java/pub/doric/shader/LinearNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/LinearNode.java @@ -54,7 +54,7 @@ public class LinearNode extends GroupNode { } @Override - protected LinearLayout build(JSObject jsObject) { + protected LinearLayout build() { return new LinearLayout(getContext()); } diff --git a/Android/doric/src/main/java/pub/doric/shader/StackNode.java b/Android/doric/src/main/java/pub/doric/shader/StackNode.java index 6f0ef046..6e2d391c 100644 --- a/Android/doric/src/main/java/pub/doric/shader/StackNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/StackNode.java @@ -45,7 +45,7 @@ public class StackNode extends GroupNode { } @Override - protected FrameLayout build(JSObject jsObject) { + protected FrameLayout build() { return new FrameLayout(getContext()); } diff --git a/Android/doric/src/main/java/pub/doric/shader/TextNode.java b/Android/doric/src/main/java/pub/doric/shader/TextNode.java index fa589c91..5b18edf0 100644 --- a/Android/doric/src/main/java/pub/doric/shader/TextNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/TextNode.java @@ -37,7 +37,7 @@ public class TextNode extends ViewNode { } @Override - protected TextView build(JSObject jsObject) { + protected TextView build() { return new TextView(getContext()); } diff --git a/Android/doric/src/main/java/pub/doric/shader/VLayoutNode.java b/Android/doric/src/main/java/pub/doric/shader/VLayoutNode.java index 243a2b73..02775139 100644 --- a/Android/doric/src/main/java/pub/doric/shader/VLayoutNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/VLayoutNode.java @@ -34,8 +34,8 @@ public class VLayoutNode extends LinearNode { } @Override - protected LinearLayout build(JSObject jsObject) { - LinearLayout linearLayout = super.build(jsObject); + protected LinearLayout build() { + LinearLayout linearLayout = super.build(); linearLayout.setOrientation(LinearLayout.VERTICAL); return linearLayout; } diff --git a/Android/doric/src/main/java/pub/doric/shader/ViewNode.java b/Android/doric/src/main/java/pub/doric/shader/ViewNode.java index 7ed2d98b..ba5576d3 100644 --- a/Android/doric/src/main/java/pub/doric/shader/ViewNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/ViewNode.java @@ -41,7 +41,6 @@ import java.util.LinkedList; */ public abstract class ViewNode extends DoricContextHolder { protected T mView; - int index; SuperNode mSuperNode; String mId; private ViewGroup.LayoutParams mLayoutParams; @@ -52,6 +51,16 @@ public abstract class ViewNode extends DoricContextHolder { 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) { mSuperNode = parentNode; } @@ -68,12 +77,12 @@ public abstract class ViewNode extends DoricContextHolder { return getDoricContext().getContext(); } - protected abstract T build(JSObject jsObject); + protected abstract T build(); public void blend(JSObject jsObject, ViewGroup.LayoutParams layoutParams) { mLayoutParams = layoutParams; if (mView == null) { - mView = build(jsObject); + mView = build(); } if (getDoricLayer() == null) { doricLayer = new DoricLayer(getContext()); diff --git a/Android/doric/src/main/java/pub/doric/shader/list/ListItemNode.java b/Android/doric/src/main/java/pub/doric/shader/list/ListItemNode.java index c06b1316..e56864e2 100644 --- a/Android/doric/src/main/java/pub/doric/shader/list/ListItemNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/list/ListItemNode.java @@ -35,7 +35,7 @@ public class ListItemNode extends StackNode { public ListItemNode(DoricContext doricContext) { super(doricContext); - this.mView = this.build(null); + this.mView = this.build(); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); this.blend(null, params); diff --git a/Android/doric/src/main/java/pub/doric/shader/list/ListNode.java b/Android/doric/src/main/java/pub/doric/shader/list/ListNode.java index 4180ac6a..5934b1c8 100644 --- a/Android/doric/src/main/java/pub/doric/shader/list/ListNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/list/ListNode.java @@ -48,7 +48,7 @@ public class ListNode extends SuperNode { } @Override - protected RecyclerView build(JSObject jsObject) { + protected RecyclerView build() { RecyclerView recyclerView = new RecyclerView(getContext()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setAdapter(this.listAdapter);