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 2cd547fc..37ba92bf 100644 --- a/Android/doric/src/main/java/pub/doric/shader/GroupNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/GroupNode.java @@ -39,7 +39,7 @@ public abstract class GroupNode extends SuperNode { } @Override - protected void blend(F view, ViewGroup.LayoutParams layoutParams, String name, JSValue prop) { + protected void blend(F view, String name, JSValue prop) { if ("children".equals(name)) { JSArray ids = prop.asArray(); mChildViewIds.clear(); @@ -47,13 +47,13 @@ public abstract class GroupNode extends SuperNode { mChildViewIds.add(ids.get(i).asString().value()); } } else { - super.blend(view, layoutParams, name, prop); + super.blend(view, name, prop); } } @Override - public void blend(JSObject jsObject, ViewGroup.LayoutParams layoutParams) { - super.blend(jsObject, layoutParams); + public void blend(JSObject jsObject) { + super.blend(jsObject); configChildNode(); } @@ -91,10 +91,9 @@ public abstract class GroupNode extends SuperNode { } else { //Not found,insert ViewNode newNode = ViewNode.create(getDoricContext(), type); - newNode.setSuperNode(this); newNode.setId(id); - ViewGroup.LayoutParams params = generateDefaultLayoutParams(); - newNode.blend(model.getProperty("props").asObject(), params); + newNode.init(this); + newNode.blend(model.getProperty("props").asObject()); mChildNodes.set(idx, newNode); mView.addView(newNode.getDoricLayer(), idx, newNode.getLayoutParams()); @@ -103,10 +102,9 @@ public abstract class GroupNode extends SuperNode { } else { //Insert ViewNode newNode = ViewNode.create(getDoricContext(), type); - newNode.setSuperNode(this); newNode.setId(id); - ViewGroup.LayoutParams params = generateDefaultLayoutParams(); - newNode.blend(model.getProperty("props").asObject(), params); + newNode.init(this); + newNode.blend(model.getProperty("props").asObject()); mChildNodes.add(newNode); mView.addView(newNode.getDoricLayer(), idx, newNode.getLayoutParams()); } @@ -123,7 +121,7 @@ public abstract class GroupNode extends SuperNode { String subNodeId = subProp.getProperty("id").asString().value(); for (ViewNode node : mChildNodes) { if (subNodeId.equals(node.getId())) { - node.blend(subProp.getProperty("props").asObject(), node.getLayoutParams()); + node.blend(subProp.getProperty("props").asObject()); break; } } 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 9ce37c9c..4c397afc 100644 --- a/Android/doric/src/main/java/pub/doric/shader/ImageNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/ImageNode.java @@ -51,7 +51,7 @@ public class ImageNode extends ViewNode { } @Override - protected void blend(ImageView view, ViewGroup.LayoutParams layoutParams, String name, JSValue prop) { + protected void blend(ImageView view, String name, JSValue prop) { if ("imageUrl".equals(name)) { Glide.with(getContext()).load(prop.asString().value()) .listener(new RequestListener() { @@ -67,7 +67,7 @@ public class ImageNode extends ViewNode { }) .into(view); } else { - super.blend(view, layoutParams, name, prop); + super.blend(view, name, prop); } } } 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 6278a98e..078ebf4d 100644 --- a/Android/doric/src/main/java/pub/doric/shader/LinearNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/LinearNode.java @@ -59,7 +59,7 @@ public class LinearNode extends GroupNode { } @Override - protected void blend(LinearLayout view, ViewGroup.LayoutParams params, String name, JSValue prop) { + protected void blend(LinearLayout view, String name, JSValue prop) { switch (name) { case "space": ShapeDrawable shapeDrawable; @@ -82,7 +82,7 @@ public class LinearNode extends GroupNode { view.setGravity(prop.asNumber().toInt()); break; default: - super.blend(view, params, name, prop); + super.blend(view, name, prop); break; } } diff --git a/Android/doric/src/main/java/pub/doric/shader/RootNode.java b/Android/doric/src/main/java/pub/doric/shader/RootNode.java index 8a1f0ff2..0eba158f 100644 --- a/Android/doric/src/main/java/pub/doric/shader/RootNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/RootNode.java @@ -42,6 +42,11 @@ public class RootNode extends StackNode { public void setRootView(FrameLayout rootView) { this.mView = rootView; + mLayoutParams = rootView.getLayoutParams(); + if (mLayoutParams == null) { + mLayoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + rootView.setLayoutParams(mLayoutParams); + } } @Override @@ -50,6 +55,6 @@ public class RootNode extends StackNode { } public void render(JSObject props) { - blend(props, getLayoutParams()); + blend(props); } } 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 6e2d391c..f57acf7f 100644 --- a/Android/doric/src/main/java/pub/doric/shader/StackNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/StackNode.java @@ -50,13 +50,13 @@ public class StackNode extends GroupNode { } @Override - protected void blend(FrameLayout view, ViewGroup.LayoutParams layoutParams, String name, JSValue prop) { + protected void blend(FrameLayout view, String name, JSValue prop) { switch (name) { case "gravity": view.setForegroundGravity(prop.asNumber().toInt()); break; default: - super.blend(view, layoutParams, name, prop); + super.blend(view, name, prop); } } 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 40727f50..672bfe01 100644 --- a/Android/doric/src/main/java/pub/doric/shader/SuperNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/SuperNode.java @@ -45,7 +45,7 @@ public abstract class SuperNode extends ViewNode { } @Override - protected void blend(V view, ViewGroup.LayoutParams layoutParams, String name, JSValue prop) { + protected void blend(V view, String name, JSValue prop) { if (name.equals("subviews")) { if (prop.isArray()) { JSArray subviews = prop.asArray(); @@ -56,7 +56,7 @@ public abstract class SuperNode extends ViewNode { } } } else { - super.blend(view, layoutParams, name, prop); + super.blend(view, name, prop); } } 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 5b18edf0..ecdedf60 100644 --- a/Android/doric/src/main/java/pub/doric/shader/TextNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/TextNode.java @@ -16,13 +16,11 @@ package pub.doric.shader; import android.util.TypedValue; -import android.view.ViewGroup; import android.widget.TextView; import pub.doric.DoricContext; import pub.doric.extension.bridge.DoricPlugin; -import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSValue; /** @@ -42,7 +40,7 @@ public class TextNode extends ViewNode { } @Override - protected void blend(TextView view, ViewGroup.LayoutParams params, String name, JSValue prop) { + protected void blend(TextView view, String name, JSValue prop) { switch (name) { case "text": view.setText(prop.asString().toString()); @@ -57,7 +55,7 @@ public class TextNode extends ViewNode { view.setGravity(prop.asNumber().toInt()); break; default: - super.blend(view, params, name, prop); + super.blend(view, name, prop); break; } } 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 02775139..6c6ba948 100644 --- a/Android/doric/src/main/java/pub/doric/shader/VLayoutNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/VLayoutNode.java @@ -20,8 +20,6 @@ import android.widget.LinearLayout; import pub.doric.DoricContext; import pub.doric.extension.bridge.DoricPlugin; -import com.github.pengfeizhou.jscore.JSObject; - /** * @Description: com.github.penfeizhou.doric.shader * @Author: pengfei.zhou 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 ba5576d3..85819503 100644 --- a/Android/doric/src/main/java/pub/doric/shader/ViewNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/ViewNode.java @@ -43,7 +43,7 @@ public abstract class ViewNode extends DoricContextHolder { protected T mView; SuperNode mSuperNode; String mId; - private ViewGroup.LayoutParams mLayoutParams; + protected ViewGroup.LayoutParams mLayoutParams; public ViewNode(DoricContext doricContext) { super(doricContext); @@ -60,11 +60,6 @@ public abstract class ViewNode extends DoricContextHolder { doricLayer.addView(mView, params); } - - public void setSuperNode(SuperNode parentNode) { - mSuperNode = parentNode; - } - public void setId(String id) { this.mId = id; } @@ -79,53 +74,44 @@ public abstract class ViewNode extends DoricContextHolder { protected abstract T build(); - public void blend(JSObject jsObject, ViewGroup.LayoutParams layoutParams) { - mLayoutParams = layoutParams; - if (mView == null) { - mView = build(); - } - if (getDoricLayer() == null) { - doricLayer = new DoricLayer(getContext()); - FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(layoutParams.width, layoutParams.height); - doricLayer.addView(mView, params); - } + public void blend(JSObject jsObject) { if (jsObject != null) { for (String prop : jsObject.propertySet()) { - blend(mView, layoutParams, prop, jsObject.getProperty(prop)); + blend(mView, prop, jsObject.getProperty(prop)); } } ViewGroup.LayoutParams params = mView.getLayoutParams(); if (params != null) { - params.width = layoutParams.width; - params.height = layoutParams.height; + params.width = mLayoutParams.width; + params.height = mLayoutParams.height; } else { - params = layoutParams; + params = mLayoutParams; } mView.setLayoutParams(params); } - protected void blend(T view, ViewGroup.LayoutParams layoutParams, String name, JSValue prop) { + protected void blend(T view, String name, JSValue prop) { switch (name) { case "width": - if (layoutParams.width >= 0) { - layoutParams.width = DoricUtils.dp2px(prop.asNumber().toFloat()); + if (mLayoutParams.width >= 0) { + mLayoutParams.width = DoricUtils.dp2px(prop.asNumber().toFloat()); } break; case "height": - if (layoutParams.height >= 0) { - layoutParams.height = DoricUtils.dp2px(prop.asNumber().toFloat()); + if (mLayoutParams.height >= 0) { + mLayoutParams.height = DoricUtils.dp2px(prop.asNumber().toFloat()); } break; case "x": - if (layoutParams instanceof ViewGroup.MarginLayoutParams) { + if (mLayoutParams instanceof ViewGroup.MarginLayoutParams) { float x = prop.asNumber().toFloat(); - ((ViewGroup.MarginLayoutParams) layoutParams).leftMargin = DoricUtils.dp2px(x); + ((ViewGroup.MarginLayoutParams) mLayoutParams).leftMargin = DoricUtils.dp2px(x); } break; case "y": - if (layoutParams instanceof ViewGroup.MarginLayoutParams) { + if (mLayoutParams instanceof ViewGroup.MarginLayoutParams) { float y = prop.asNumber().toFloat(); - ((ViewGroup.MarginLayoutParams) layoutParams).topMargin = DoricUtils.dp2px(y); + ((ViewGroup.MarginLayoutParams) mLayoutParams).topMargin = DoricUtils.dp2px(y); } break; case "bgColor": 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 08d54cb7..1b9f8764 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 @@ -52,7 +52,7 @@ public class ListAdapter extends RecyclerView.Adapter { } @Override - public void blend(JSObject jsObject, ViewGroup.LayoutParams layoutParams) { - super.blend(jsObject, layoutParams); + public void blend(JSObject jsObject) { + super.blend(jsObject); if (mView != null) { mView.post(new Runnable() { @Override @@ -69,7 +67,7 @@ public class ListNode extends SuperNode { } @Override - protected void blend(RecyclerView view, ViewGroup.LayoutParams layoutParams, String name, JSValue prop) { + protected void blend(RecyclerView view, String name, JSValue prop) { switch (name) { case "itemCount": this.listAdapter.itemCount = prop.asNumber().toInt(); @@ -83,7 +81,7 @@ public class ListNode extends SuperNode { this.listAdapter.batchCount = 15; break; default: - super.blend(view, layoutParams, name, prop); + super.blend(view, name, prop); break; } }