Layout add minWidth minHeight maxWidth maxHeight
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
package pub.doric.shader;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
|
@@ -92,54 +92,7 @@ public abstract class SuperNode<V extends View> extends ViewNode<V> {
|
||||
protected abstract void blendSubNode(JSObject subProperties);
|
||||
|
||||
protected void blendSubLayoutConfig(ViewNode viewNode, JSObject jsObject) {
|
||||
JSValue margin = jsObject.getProperty("margin");
|
||||
JSValue widthSpec = jsObject.getProperty("widthSpec");
|
||||
JSValue heightSpec = jsObject.getProperty("heightSpec");
|
||||
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:
|
||||
layoutParams.width = Math.max(0, layoutParams.width);
|
||||
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:
|
||||
layoutParams.height = Math.max(0, layoutParams.height);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (margin.isObject() && layoutParams instanceof ViewGroup.MarginLayoutParams) {
|
||||
JSValue topVal = margin.asObject().getProperty("top");
|
||||
if (topVal.isNumber()) {
|
||||
((ViewGroup.MarginLayoutParams) layoutParams).topMargin = DoricUtils.dp2px(topVal.asNumber().toFloat());
|
||||
}
|
||||
JSValue leftVal = margin.asObject().getProperty("left");
|
||||
if (leftVal.isNumber()) {
|
||||
((ViewGroup.MarginLayoutParams) layoutParams).leftMargin = DoricUtils.dp2px(leftVal.asNumber().toFloat());
|
||||
}
|
||||
JSValue rightVal = margin.asObject().getProperty("right");
|
||||
if (rightVal.isNumber()) {
|
||||
((ViewGroup.MarginLayoutParams) layoutParams).rightMargin = DoricUtils.dp2px(rightVal.asNumber().toFloat());
|
||||
}
|
||||
JSValue bottomVal = margin.asObject().getProperty("bottom");
|
||||
if (bottomVal.isNumber()) {
|
||||
((ViewGroup.MarginLayoutParams) layoutParams).bottomMargin = DoricUtils.dp2px(bottomVal.asNumber().toFloat());
|
||||
}
|
||||
}
|
||||
viewNode.blendLayoutConfig(jsObject);
|
||||
}
|
||||
|
||||
private void mixin(JSObject src, JSObject target) {
|
||||
|
@@ -37,8 +37,6 @@ import android.widget.LinearLayout;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
|
||||
|
||||
import com.facebook.yoga.YogaNode;
|
||||
import com.facebook.yoga.android.YogaLayout;
|
||||
import com.github.pengfeizhou.jscore.JSArray;
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||
@@ -55,7 +53,6 @@ import pub.doric.DoricRegistry;
|
||||
import pub.doric.async.AsyncResult;
|
||||
import pub.doric.extension.bridge.DoricMethod;
|
||||
import pub.doric.extension.bridge.DoricPromise;
|
||||
import pub.doric.shader.flex.FlexNode;
|
||||
import pub.doric.utils.DoricConstant;
|
||||
import pub.doric.utils.DoricContextHolder;
|
||||
import pub.doric.utils.DoricLog;
|
||||
@@ -531,7 +528,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
);
|
||||
}
|
||||
|
||||
private void blendLayoutConfig(JSObject jsObject) {
|
||||
protected void blendLayoutConfig(JSObject jsObject) {
|
||||
JSValue margin = jsObject.getProperty("margin");
|
||||
JSValue widthSpec = jsObject.getProperty("widthSpec");
|
||||
JSValue heightSpec = jsObject.getProperty("heightSpec");
|
||||
@@ -584,6 +581,14 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
if (jsValue.isNumber() && layoutParams instanceof FrameLayout.LayoutParams) {
|
||||
((FrameLayout.LayoutParams) layoutParams).gravity = jsValue.asNumber().toInt();
|
||||
}
|
||||
JSValue minWidthValue = jsObject.getProperty("minWidth");
|
||||
if (minWidthValue.isNumber()) {
|
||||
mView.setMinimumWidth(DoricUtils.dp2px(minWidthValue.asNumber().toFloat()));
|
||||
}
|
||||
JSValue minHeightValue = jsObject.getProperty("minHeight");
|
||||
if (minHeightValue.isNumber()) {
|
||||
mView.setMinimumHeight(DoricUtils.dp2px(minHeightValue.asNumber().toFloat()));
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isAnimating() {
|
||||
|
Reference in New Issue
Block a user