add vh layout
This commit is contained in:
@@ -3,10 +3,12 @@ package com.github.penfeizhou.doric;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.github.penfeizhou.doric.plugin.ShaderPlugin;
|
||||
import com.github.penfeizhou.doric.shader.HLayoutNode;
|
||||
import com.github.penfeizhou.doric.shader.ImageNode;
|
||||
import com.github.penfeizhou.doric.shader.RootNode;
|
||||
import com.github.penfeizhou.doric.shader.StackNode;
|
||||
import com.github.penfeizhou.doric.shader.TextNode;
|
||||
import com.github.penfeizhou.doric.shader.VLayoutNode;
|
||||
import com.github.penfeizhou.doric.shader.ViewNode;
|
||||
import com.github.penfeizhou.doric.utils.DoricMetaInfo;
|
||||
import com.github.penfeizhou.doric.plugin.DoricJavaPlugin;
|
||||
@@ -47,6 +49,8 @@ public class DoricRegistry {
|
||||
this.registerViewNode(TextNode.class);
|
||||
this.registerViewNode(ImageNode.class);
|
||||
this.registerViewNode(StackNode.class);
|
||||
this.registerViewNode(VLayoutNode.class);
|
||||
this.registerViewNode(HLayoutNode.class);
|
||||
initRegistry(this);
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,26 @@
|
||||
package com.github.penfeizhou.doric.shader;
|
||||
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.github.penfeizhou.doric.DoricContext;
|
||||
import com.github.penfeizhou.doric.extension.bridge.DoricPlugin;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
|
||||
/**
|
||||
* @Description: com.github.penfeizhou.doric.shader
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-23
|
||||
*/
|
||||
@DoricPlugin(name = "HLayout")
|
||||
public class HLayoutNode extends LinearNode {
|
||||
public HLayoutNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinearLayout build(JSObject jsObject) {
|
||||
LinearLayout linearLayout = super.build(jsObject);
|
||||
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
|
||||
return linearLayout;
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
package com.github.penfeizhou.doric.shader;
|
||||
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.github.penfeizhou.doric.DoricContext;
|
||||
import com.github.penfeizhou.doric.utils.DoricUtils;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
/**
|
||||
* @Description: com.github.penfeizhou.doric.shader
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-23
|
||||
*/
|
||||
public class LinearNode extends GroupNode<LinearLayout> {
|
||||
public LinearNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinearLayout build(JSObject jsObject) {
|
||||
return new LinearLayout(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void blend(LinearLayout view, String name, JSValue prop) {
|
||||
switch (name) {
|
||||
case "space":
|
||||
ShapeDrawable shapeDrawable;
|
||||
if (view.getDividerDrawable() == null) {
|
||||
shapeDrawable = new ShapeDrawable();
|
||||
shapeDrawable.setAlpha(0);
|
||||
view.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
|
||||
} else {
|
||||
shapeDrawable = (ShapeDrawable) view.getDividerDrawable();
|
||||
view.setDividerDrawable(null);
|
||||
}
|
||||
if (view.getOrientation() == LinearLayout.VERTICAL) {
|
||||
shapeDrawable.setIntrinsicHeight(DoricUtils.dp2px(prop.asNumber().toFloat()));
|
||||
} else {
|
||||
shapeDrawable.setIntrinsicWidth(DoricUtils.dp2px(prop.asNumber().toFloat()));
|
||||
}
|
||||
view.setDividerDrawable(shapeDrawable);
|
||||
break;
|
||||
case "gravity":
|
||||
view.setGravity(prop.asNumber().toInt());
|
||||
break;
|
||||
default:
|
||||
super.blend(view, name, prop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,6 +5,7 @@ import android.widget.FrameLayout;
|
||||
import com.github.penfeizhou.doric.DoricContext;
|
||||
import com.github.penfeizhou.doric.extension.bridge.DoricPlugin;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
/**
|
||||
* @Description: com.github.penfeizhou.doric.widget
|
||||
@@ -21,4 +22,15 @@ public class StackNode extends GroupNode<FrameLayout> {
|
||||
public FrameLayout build(JSObject jsObject) {
|
||||
return new FrameLayout(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void blend(FrameLayout view, String name, JSValue prop) {
|
||||
switch (name) {
|
||||
case "gravity":
|
||||
view.setForegroundGravity(prop.asNumber().toInt());
|
||||
break;
|
||||
default:
|
||||
super.blend(view, name, prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,27 @@
|
||||
package com.github.penfeizhou.doric.shader;
|
||||
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.github.penfeizhou.doric.DoricContext;
|
||||
import com.github.penfeizhou.doric.extension.bridge.DoricPlugin;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
|
||||
/**
|
||||
* @Description: com.github.penfeizhou.doric.shader
|
||||
* @Author: pengfei.zhou
|
||||
* @CreateDate: 2019-07-23
|
||||
*/
|
||||
@DoricPlugin(name = "VLayout")
|
||||
public class VLayoutNode extends LinearNode {
|
||||
public VLayoutNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinearLayout build(JSObject jsObject) {
|
||||
LinearLayout linearLayout = super.build(jsObject);
|
||||
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
return linearLayout;
|
||||
}
|
||||
|
||||
}
|
@@ -58,10 +58,18 @@ public abstract class ViewNode<T extends View> extends DoricComponent {
|
||||
protected void blend(T view, String name, JSValue prop) {
|
||||
switch (name) {
|
||||
case "width":
|
||||
view.getLayoutParams().width = DoricUtils.dp2px(prop.asNumber().toFloat());
|
||||
if (prop.asNumber().toInt() < 0) {
|
||||
view.getLayoutParams().width = prop.asNumber().toInt();
|
||||
} else {
|
||||
view.getLayoutParams().width = DoricUtils.dp2px(prop.asNumber().toFloat());
|
||||
}
|
||||
break;
|
||||
case "height":
|
||||
view.getLayoutParams().height = DoricUtils.dp2px(prop.asNumber().toFloat());
|
||||
if (prop.asNumber().toInt() < 0) {
|
||||
view.getLayoutParams().height = prop.asNumber().toInt();
|
||||
} else {
|
||||
view.getLayoutParams().height = DoricUtils.dp2px(prop.asNumber().toFloat());
|
||||
}
|
||||
break;
|
||||
case "x":
|
||||
if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
|
||||
|
Reference in New Issue
Block a user