feat:complete defination of LayoutConfig

This commit is contained in:
pengfei.zhou
2019-10-23 15:59:55 +08:00
parent eeed67b57a
commit f78f3ed7d8
10 changed files with 107 additions and 73 deletions

View File

@@ -67,8 +67,8 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
private void initJSExecutor() {
// mDoricJSE = new DoricNativeJSExecutor();
mDoricJSE = new DoricRemoteJSExecutor();
mDoricJSE = new DoricNativeJSExecutor();
// mDoricJSE = new DoricRemoteJSExecutor();
mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_LOG, new JavaFunction() {
@Override
public JavaValue exec(JSDecoder[] args) {

View File

@@ -116,12 +116,42 @@ public abstract class GroupNode<F extends ViewGroup> extends ViewNode<F> {
}
protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
return new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
return new ViewGroup.LayoutParams(0, 0);
}
protected void blendChild(ViewNode viewNode, JSObject jsObject) {
JSValue jsValue = jsObject.getProperty("margin");
JSValue widthSpec = jsObject.getProperty("widthSpec");
JSValue heightSpec = jsObject.getProperty("widthSpec");
ViewGroup.LayoutParams layoutParams = viewNode.getLayoutParams();
if (widthSpec.isNumber()) {
switch (widthSpec.asNumber().toInt()) {
case 1:
layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
break;
case 2:
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
break;
default:
break;
}
}
if (heightSpec.isNumber()) {
switch (heightSpec.asNumber().toInt()) {
case 1:
layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
break;
case 2:
layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
break;
default:
break;
}
}
if (jsValue.isObject() && layoutParams instanceof ViewGroup.MarginLayoutParams) {
JSValue topVal = jsValue.asObject().getProperty("top");
if (topVal.isNumber()) {

View File

@@ -50,7 +50,7 @@ public class LinearNode extends GroupNode<LinearLayout> {
@Override
protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
return new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
return new LinearLayout.LayoutParams(0, 0);
}
@Override

View File

@@ -62,6 +62,6 @@ public class StackNode extends GroupNode<FrameLayout> {
@Override
protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
return new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
return new FrameLayout.LayoutParams(0, 0);
}
}

View File

@@ -86,16 +86,12 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
protected void blend(T view, ViewGroup.LayoutParams layoutParams, String name, JSValue prop) {
switch (name) {
case "width":
if (prop.asNumber().toInt() < 0) {
layoutParams.width = prop.asNumber().toInt();
} else {
if (layoutParams.width >= 0) {
layoutParams.width = DoricUtils.dp2px(prop.asNumber().toFloat());
}
break;
case "height":
if (prop.asNumber().toInt() < 0) {
layoutParams.height = prop.asNumber().toInt();
} else {
if (layoutParams.height >= 0) {
layoutParams.height = DoricUtils.dp2px(prop.asNumber().toFloat());
}
break;