Android implement maxWidth maxHeight
This commit is contained in:
parent
80811a3bf6
commit
1e112055db
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package pub.doric.shader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
@ -31,10 +32,48 @@ import com.github.pengfeizhou.jscore.JSValue;
|
||||
* @CreateDate: 2019-07-23
|
||||
*/
|
||||
public class LinearNode extends GroupNode<LinearLayout> {
|
||||
|
||||
private static class MaximumLinearLayout extends LinearLayout {
|
||||
private int maxWidth = Integer.MAX_VALUE;
|
||||
private int maxHeight = Integer.MAX_VALUE;
|
||||
|
||||
|
||||
public MaximumLinearLayout(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
int width = getMeasuredWidth();
|
||||
int height = getMeasuredHeight();
|
||||
if (width > maxWidth || height > maxHeight) {
|
||||
width = Math.min(width, maxWidth);
|
||||
height = Math.min(height, maxHeight);
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST);
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public LinearNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void blendLayoutConfig(JSObject jsObject) {
|
||||
super.blendLayoutConfig(jsObject);
|
||||
JSValue maxWidth = jsObject.getProperty("maxWidth");
|
||||
if (maxWidth.isNumber()) {
|
||||
((MaximumLinearLayout) mView).maxWidth = DoricUtils.dp2px(maxWidth.asNumber().toFloat());
|
||||
}
|
||||
JSValue maxHeight = jsObject.getProperty("maxHeight");
|
||||
if (maxHeight.isNumber()) {
|
||||
((MaximumLinearLayout) mView).maxHeight = DoricUtils.dp2px(maxHeight.asNumber().toFloat());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void blendSubLayoutConfig(ViewNode viewNode, JSObject layoutConfig) {
|
||||
super.blendSubLayoutConfig(viewNode, layoutConfig);
|
||||
@ -55,7 +94,7 @@ public class LinearNode extends GroupNode<LinearLayout> {
|
||||
|
||||
@Override
|
||||
protected LinearLayout build() {
|
||||
return new LinearLayout(getContext());
|
||||
return new MaximumLinearLayout(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,7 +15,9 @@
|
||||
*/
|
||||
package pub.doric.shader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
@ -49,11 +51,47 @@ public class ScrollerNode extends SuperNode<HVScrollView> implements IDoricScrol
|
||||
private String onScrollEndFuncId;
|
||||
private DoricJSDispatcher jsDispatcher = new DoricJSDispatcher();
|
||||
|
||||
private static class MaximumScrollView extends HVScrollView {
|
||||
private int maxWidth = Integer.MAX_VALUE;
|
||||
private int maxHeight = Integer.MAX_VALUE;
|
||||
|
||||
|
||||
public MaximumScrollView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
int width = getMeasuredWidth();
|
||||
int height = getMeasuredHeight();
|
||||
if (width > maxWidth || height > maxHeight) {
|
||||
width = Math.min(width, maxWidth);
|
||||
height = Math.min(height, maxHeight);
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST);
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ScrollerNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void blendLayoutConfig(JSObject jsObject) {
|
||||
super.blendLayoutConfig(jsObject);
|
||||
JSValue maxWidth = jsObject.getProperty("maxWidth");
|
||||
if (maxWidth.isNumber()) {
|
||||
((MaximumScrollView) mView).maxWidth = DoricUtils.dp2px(maxWidth.asNumber().toFloat());
|
||||
}
|
||||
JSValue maxHeight = jsObject.getProperty("maxHeight");
|
||||
if (maxHeight.isNumber()) {
|
||||
((MaximumScrollView) mView).maxHeight = DoricUtils.dp2px(maxHeight.asNumber().toFloat());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewNode getSubNodeById(String id) {
|
||||
return id.equals(mChildNode.getId()) ? mChildNode : null;
|
||||
@ -68,7 +106,7 @@ public class ScrollerNode extends SuperNode<HVScrollView> implements IDoricScrol
|
||||
|
||||
@Override
|
||||
protected HVScrollView build() {
|
||||
HVScrollView hvScrollView = new HVScrollView(getContext());
|
||||
HVScrollView hvScrollView = new MaximumScrollView(getContext());
|
||||
hvScrollView.setOnScrollChangeListener(new HVScrollView.OnScrollChangeListener() {
|
||||
|
||||
@Override
|
||||
|
@ -15,11 +15,14 @@
|
||||
*/
|
||||
package pub.doric.shader;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.extension.bridge.DoricPlugin;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
@ -31,10 +34,48 @@ import com.github.pengfeizhou.jscore.JSValue;
|
||||
*/
|
||||
@DoricPlugin(name = "Stack")
|
||||
public class StackNode extends GroupNode<FrameLayout> {
|
||||
private static class MaximumFrameLayout extends FrameLayout {
|
||||
private int maxWidth = Integer.MAX_VALUE;
|
||||
private int maxHeight = Integer.MAX_VALUE;
|
||||
|
||||
|
||||
public MaximumFrameLayout(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
int width = getMeasuredWidth();
|
||||
int height = getMeasuredHeight();
|
||||
if (width > maxWidth || height > maxHeight) {
|
||||
width = Math.min(width, maxWidth);
|
||||
height = Math.min(height, maxHeight);
|
||||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST);
|
||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public StackNode(DoricContext doricContext) {
|
||||
super(doricContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void blendLayoutConfig(JSObject jsObject) {
|
||||
super.blendLayoutConfig(jsObject);
|
||||
JSValue maxWidth = jsObject.getProperty("maxWidth");
|
||||
if (maxWidth.isNumber()) {
|
||||
((MaximumFrameLayout) mView).maxWidth = DoricUtils.dp2px(maxWidth.asNumber().toFloat());
|
||||
}
|
||||
JSValue maxHeight = jsObject.getProperty("maxHeight");
|
||||
if (maxHeight.isNumber()) {
|
||||
((MaximumFrameLayout) mView).maxHeight = DoricUtils.dp2px(maxHeight.asNumber().toFloat());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void blendSubLayoutConfig(ViewNode viewNode, JSObject jsObject) {
|
||||
super.blendSubLayoutConfig(viewNode, jsObject);
|
||||
@ -46,7 +87,7 @@ public class StackNode extends GroupNode<FrameLayout> {
|
||||
|
||||
@Override
|
||||
protected FrameLayout build() {
|
||||
return new FrameLayout(getContext());
|
||||
return new MaximumFrameLayout(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,7 @@ import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
@ -48,6 +49,19 @@ public class TextNode extends ViewNode<TextView> {
|
||||
return tv;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void blendLayoutConfig(JSObject jsObject) {
|
||||
super.blendLayoutConfig(jsObject);
|
||||
JSValue maxWidth = jsObject.getProperty("maxWidth");
|
||||
if (maxWidth.isNumber()) {
|
||||
mView.setMaxWidth(DoricUtils.dp2px(maxWidth.asNumber().toFloat()));
|
||||
}
|
||||
JSValue maxHeight = jsObject.getProperty("maxHeight");
|
||||
if (maxHeight.isNumber()) {
|
||||
mView.setMaxHeight(DoricUtils.dp2px(maxWidth.asNumber().toFloat()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void blend(TextView view, String name, JSValue prop) {
|
||||
switch (name) {
|
||||
|
@ -27,22 +27,6 @@ class LayoutDemo extends Panel {
|
||||
height: 100,
|
||||
}
|
||||
}),
|
||||
// stack([],
|
||||
// {
|
||||
// backgroundColor: colors[3],
|
||||
// flexConfig: {
|
||||
// width: 500,
|
||||
// height: 300,
|
||||
// }
|
||||
// }),
|
||||
// stack([],
|
||||
// {
|
||||
// backgroundColor: colors[4],
|
||||
// flexConfig: {
|
||||
// width: 500,
|
||||
// height: 500,
|
||||
// }
|
||||
// }),
|
||||
],
|
||||
{
|
||||
flexConfig: {
|
||||
@ -54,8 +38,8 @@ class LayoutDemo extends Panel {
|
||||
layoutConfig: {
|
||||
widthSpec: LayoutSpec.FIT,
|
||||
heightSpec: LayoutSpec.FIT,
|
||||
minHeight: 300,
|
||||
maxHeight: 300,
|
||||
minHeight: 200,
|
||||
maxHeight: 400,
|
||||
},
|
||||
backgroundColor: colors[0].alpha(0.3),
|
||||
})
|
||||
|
Reference in New Issue
Block a user