layoutconfig support margin
This commit is contained in:
parent
cfde85b773
commit
d180c6df22
@ -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<F extends ViewGroup> extends ViewNode<F> {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -18,7 +18,7 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageView build(JSObject jsObject) {
|
||||
protected ImageView build(JSObject jsObject) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -20,11 +20,16 @@ public class LinearNode extends GroupNode<LinearLayout> {
|
||||
}
|
||||
|
||||
@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<LinearLayout> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinearLayout build(JSObject jsObject) {
|
||||
protected LinearLayout build(JSObject jsObject) {
|
||||
return new LinearLayout(getContext());
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,8 @@ public class StackNode extends GroupNode<FrameLayout> {
|
||||
}
|
||||
|
||||
@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<FrameLayout> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public FrameLayout build(JSObject jsObject) {
|
||||
protected FrameLayout build(JSObject jsObject) {
|
||||
return new FrameLayout(getContext());
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ public class TextNode extends ViewNode<TextView> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextView build(JSObject jsObject) {
|
||||
protected TextView build(JSObject jsObject) {
|
||||
return new TextView(getContext());
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -41,7 +41,7 @@ public abstract class ViewNode<T extends View> 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;
|
||||
|
@ -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<CountModel, CounterView> {
|
||||
}
|
||||
|
||||
|
||||
@Entry
|
||||
class MyPage extends VMPanel<CountModel, CounterView>{
|
||||
|
||||
getVMClass() {
|
||||
@ -73,3 +72,48 @@ class MyPage extends VMPanel<CountModel, CounterView>{
|
||||
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<Snake, SnakeView>{
|
||||
binding(v: SnakeView, model: Snake) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Entry
|
||||
class SnakePanel extends VMPanel<Snake, SnakeView>{
|
||||
getVMClass() {
|
||||
return SnakeVM
|
||||
}
|
||||
getModel() {
|
||||
return new Snake
|
||||
}
|
||||
|
||||
getViewHolder() {
|
||||
return new SnakeView
|
||||
}
|
||||
}
|
@ -65,7 +65,7 @@ export abstract class ViewModel<M extends Object, V extends ViewHolder> {
|
||||
build(root: Group) {
|
||||
this.viewHolder.build(root)
|
||||
this.bind((data: M) => {
|
||||
this.binding(this.viewHolder, this.model)
|
||||
this.binding(this.viewHolder, data)
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user