feat:extract view's layout setting method
This commit is contained in:
parent
b3ef2004fc
commit
33a671af85
@ -108,26 +108,16 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
|||||||
protected void blend(T view, String name, JSValue prop) {
|
protected void blend(T view, String name, JSValue prop) {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case "width":
|
case "width":
|
||||||
if (mLayoutParams.width >= 0) {
|
setWidth(prop.asNumber().toFloat());
|
||||||
mLayoutParams.width = DoricUtils.dp2px(prop.asNumber().toFloat());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "height":
|
case "height":
|
||||||
if (mLayoutParams.height >= 0) {
|
setHeight(prop.asNumber().toFloat());
|
||||||
mLayoutParams.height = DoricUtils.dp2px(prop.asNumber().toFloat());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "x":
|
case "x":
|
||||||
if (mLayoutParams instanceof ViewGroup.MarginLayoutParams) {
|
setX(prop.asNumber().toFloat());
|
||||||
float x = prop.asNumber().toFloat();
|
|
||||||
((ViewGroup.MarginLayoutParams) mLayoutParams).leftMargin = DoricUtils.dp2px(x);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "y":
|
case "y":
|
||||||
if (mLayoutParams instanceof ViewGroup.MarginLayoutParams) {
|
setY(prop.asNumber().toFloat());
|
||||||
float y = prop.asNumber().toFloat();
|
|
||||||
((ViewGroup.MarginLayoutParams) mLayoutParams).topMargin = DoricUtils.dp2px(y);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "bgColor":
|
case "bgColor":
|
||||||
view.setBackgroundColor(prop.asNumber().toInt());
|
view.setBackgroundColor(prop.asNumber().toInt());
|
||||||
@ -142,9 +132,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "layoutConfig":
|
case "layoutConfig":
|
||||||
if (prop.isObject() && mSuperNode != null) {
|
setLayoutConfig(prop.asObject());
|
||||||
mSuperNode.blendSubLayoutConfig(this, prop.asObject());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "border":
|
case "border":
|
||||||
if (prop.isObject() && doricLayer != null) {
|
if (prop.isObject() && doricLayer != null) {
|
||||||
@ -225,4 +213,34 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
|||||||
public String getId() {
|
public String getId() {
|
||||||
return mId;
|
return mId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setWidth(float width) {
|
||||||
|
if (mLayoutParams.width >= 0) {
|
||||||
|
mLayoutParams.width = DoricUtils.dp2px(width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setHeight(float height) {
|
||||||
|
if (mLayoutParams.height >= 0) {
|
||||||
|
mLayoutParams.height = DoricUtils.dp2px(height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setX(float x) {
|
||||||
|
if (mLayoutParams instanceof ViewGroup.MarginLayoutParams) {
|
||||||
|
((ViewGroup.MarginLayoutParams) mLayoutParams).leftMargin = DoricUtils.dp2px(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setY(float y) {
|
||||||
|
if (mLayoutParams instanceof ViewGroup.MarginLayoutParams) {
|
||||||
|
((ViewGroup.MarginLayoutParams) mLayoutParams).topMargin = DoricUtils.dp2px(y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setLayoutConfig(JSObject layoutConfig) {
|
||||||
|
if (mSuperNode != null) {
|
||||||
|
mSuperNode.blendSubLayoutConfig(this, layoutConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user