diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java index 01ab1b6f..061d5811 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java @@ -4,6 +4,7 @@ import android.util.SparseArray; import android.view.ViewGroup; import com.github.penfeizhou.doric.DoricContext; +import com.github.penfeizhou.doric.utils.DoricUtils; import com.github.pengfeizhou.jscore.JSArray; import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSValue; @@ -79,5 +80,26 @@ public abstract class GroupNode extends ViewNode { return new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); } - public abstract void blendChild(ViewNode viewNode, JSObject jsObject); + protected void blendChild(ViewNode viewNode, JSObject jsObject) { + JSValue jsValue = jsObject.getProperty("margin"); + ViewGroup.LayoutParams layoutParams = viewNode.getLayoutParams(); + if (jsValue.isObject() && layoutParams instanceof ViewGroup.MarginLayoutParams) { + JSValue topVal = jsValue.asObject().getProperty("top"); + if (topVal.isNumber()) { + ((ViewGroup.MarginLayoutParams) layoutParams).topMargin = DoricUtils.dp2px(topVal.asNumber().toFloat()); + } + JSValue leftVal = jsValue.asObject().getProperty("left"); + if (leftVal.isNumber()) { + ((ViewGroup.MarginLayoutParams) layoutParams).leftMargin = DoricUtils.dp2px(leftVal.asNumber().toFloat()); + } + JSValue rightVal = jsValue.asObject().getProperty("right"); + if (rightVal.isNumber()) { + ((ViewGroup.MarginLayoutParams) layoutParams).rightMargin = DoricUtils.dp2px(rightVal.asNumber().toFloat()); + } + JSValue bottomVal = jsValue.asObject().getProperty("bottom"); + if (bottomVal.isNumber()) { + ((ViewGroup.MarginLayoutParams) layoutParams).bottomMargin = DoricUtils.dp2px(bottomVal.asNumber().toFloat()); + } + } + } } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/HLayoutNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/HLayoutNode.java index b5ae2cbe..0db3ff2d 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/HLayoutNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/HLayoutNode.java @@ -18,7 +18,7 @@ public class HLayoutNode extends LinearNode { } @Override - public LinearLayout build(JSObject jsObject) { + protected LinearLayout build(JSObject jsObject) { LinearLayout linearLayout = super.build(jsObject); linearLayout.setOrientation(LinearLayout.HORIZONTAL); return linearLayout; diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ImageNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ImageNode.java index ef758a34..7ab221d8 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ImageNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ImageNode.java @@ -18,7 +18,7 @@ public class ImageNode extends ViewNode { } @Override - public ImageView build(JSObject jsObject) { + protected ImageView build(JSObject jsObject) { return null; } } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/LinearNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/LinearNode.java index 2cb0d857..e13ff0b2 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/LinearNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/LinearNode.java @@ -20,11 +20,16 @@ public class LinearNode extends GroupNode { } @Override - public void blendChild(ViewNode viewNode, JSObject layoutConfig) { + protected void blendChild(ViewNode viewNode, JSObject layoutConfig) { + super.blendChild(viewNode, layoutConfig); JSValue jsValue = layoutConfig.getProperty("alignment"); if (jsValue.isNumber()) { ((LinearLayout.LayoutParams) viewNode.getLayoutParams()).gravity = jsValue.asNumber().toInt(); } + JSValue weight = layoutConfig.getProperty("weight"); + if (weight.isNumber()) { + ((LinearLayout.LayoutParams) viewNode.getLayoutParams()).weight = weight.asNumber().toInt(); + } } @Override @@ -33,7 +38,7 @@ public class LinearNode extends GroupNode { } @Override - public LinearLayout build(JSObject jsObject) { + protected LinearLayout build(JSObject jsObject) { return new LinearLayout(getContext()); } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/StackNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/StackNode.java index a4b0516b..7b2436de 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/StackNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/StackNode.java @@ -20,7 +20,8 @@ public class StackNode extends GroupNode { } @Override - public void blendChild(ViewNode viewNode, JSObject jsObject) { + protected void blendChild(ViewNode viewNode, JSObject jsObject) { + super.blendChild(viewNode, jsObject); JSValue jsValue = jsObject.getProperty("alignment"); if (jsValue.isNumber()) { ((FrameLayout.LayoutParams) viewNode.getLayoutParams()).gravity = jsValue.asNumber().toInt(); @@ -28,7 +29,7 @@ public class StackNode extends GroupNode { } @Override - public FrameLayout build(JSObject jsObject) { + protected FrameLayout build(JSObject jsObject) { return new FrameLayout(getContext()); } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/TextNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/TextNode.java index 62b623e2..3197edbe 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/TextNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/TextNode.java @@ -21,7 +21,7 @@ public class TextNode extends ViewNode { } @Override - public TextView build(JSObject jsObject) { + protected TextView build(JSObject jsObject) { return new TextView(getContext()); } diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/VLayoutNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/VLayoutNode.java index bb5d8704..2b5d4939 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/VLayoutNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/VLayoutNode.java @@ -18,7 +18,7 @@ public class VLayoutNode extends LinearNode { } @Override - public LinearLayout build(JSObject jsObject) { + protected LinearLayout build(JSObject jsObject) { LinearLayout linearLayout = super.build(jsObject); linearLayout.setOrientation(LinearLayout.VERTICAL); return linearLayout; diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ViewNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ViewNode.java index 9bf8960c..84643e3b 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ViewNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/ViewNode.java @@ -41,7 +41,7 @@ public abstract class ViewNode extends DoricComponent { return getDoricContext().getContext(); } - public abstract T build(JSObject jsObject); + protected abstract T build(JSObject jsObject); void blend(JSObject jsObject, ViewGroup.LayoutParams layoutParams) { mLayoutParams = layoutParams; diff --git a/js-framework/demo.ts b/js-framework/demo.ts index 2f56af94..4fb29bec 100644 --- a/js-framework/demo.ts +++ b/js-framework/demo.ts @@ -1,4 +1,4 @@ -import { ViewHolder, VMPanel, View, ViewModel, WRAP_CONTENT, Gravity, Mutable, NativeCall, Text, Color, VLayout, Panel, log, logw, loge, Group, Stack, } from "./index" +import { StackConfig, ViewHolder, VMPanel, View, ViewModel, WRAP_CONTENT, Gravity, Mutable, NativeCall, Text, Color, VLayout, Panel, log, logw, loge, Group, Stack, } from "./index" interface CountModel { count: number @@ -45,7 +45,6 @@ class CounterVM extends ViewModel { } -@Entry class MyPage extends VMPanel{ getVMClass() { @@ -72,4 +71,49 @@ class MyPage extends VMPanel{ logw("Hello.HEGO") loge("Hello.HEGO") } +} + + + + +class Snake { + +} + +class SnakeView extends ViewHolder { + + build(root: Group): void { + root.bgColor = Color.parse('#000000') + const title = new Text + title.text = "Snake" + title.textSize = 20 + title.textColor = Color.parse("#ffffff") + title.layoutConfig = { + alignment: new Gravity().centerX().top(), + margin: { + top: 20 + } + } as StackConfig + root.addChild(title) + } +} + +class SnakeVM extends ViewModel{ + binding(v: SnakeView, model: Snake) { + + } +} + +@Entry +class SnakePanel extends VMPanel{ + getVMClass() { + return SnakeVM + } + getModel() { + return new Snake + } + + getViewHolder() { + return new SnakeView + } } \ No newline at end of file diff --git a/js-framework/src/vm/mvvm.ts b/js-framework/src/vm/mvvm.ts index 1a7c8654..d0e2f2e2 100644 --- a/js-framework/src/vm/mvvm.ts +++ b/js-framework/src/vm/mvvm.ts @@ -65,7 +65,7 @@ export abstract class ViewModel { build(root: Group) { this.viewHolder.build(root) this.bind((data: M) => { - this.binding(this.viewHolder, this.model) + this.binding(this.viewHolder, data) }) }