feat:fix Android weight props blend error
This commit is contained in:
parent
1b08c227ef
commit
b3ef2004fc
@ -16,6 +16,7 @@
|
||||
package pub.doric.shader;
|
||||
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.widget.TextView;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
@ -52,7 +53,7 @@ public class TextNode extends ViewNode<TextView> {
|
||||
view.setTextColor(prop.asNumber().toInt());
|
||||
break;
|
||||
case "textAlignment":
|
||||
view.setGravity(prop.asNumber().toInt());
|
||||
view.setGravity(prop.asNumber().toInt() | Gravity.CENTER_VERTICAL);
|
||||
break;
|
||||
default:
|
||||
super.blend(view, name, prop);
|
||||
|
@ -19,6 +19,7 @@ import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricRegistry;
|
||||
@ -66,7 +67,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
this.mId = id;
|
||||
}
|
||||
|
||||
public String getType(){
|
||||
public String getType() {
|
||||
return mType;
|
||||
}
|
||||
|
||||
@ -93,6 +94,14 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
|
||||
} else {
|
||||
params = mLayoutParams;
|
||||
}
|
||||
if (mLayoutParams instanceof LinearLayout.LayoutParams && ((LinearLayout.LayoutParams) mLayoutParams).weight > 0) {
|
||||
if (mSuperNode instanceof VLayoutNode) {
|
||||
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
} else if (mSuperNode instanceof HLayoutNode) {
|
||||
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||
}
|
||||
}
|
||||
|
||||
mView.setLayoutParams(params);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout } from "doric";
|
||||
import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout } from "doric";
|
||||
const colors = [
|
||||
"#f0932b",
|
||||
"#eb4d4b",
|
||||
@ -26,23 +26,44 @@ class ListPanel extends Panel {
|
||||
list({
|
||||
itemCount: 1000,
|
||||
renderItem: (idx: number) => {
|
||||
return listItem(text({
|
||||
return listItem(
|
||||
hlayout([
|
||||
text({
|
||||
layoutConfig: {
|
||||
widthSpec: LayoutSpec.AT_MOST,
|
||||
heightSpec: LayoutSpec.WRAP_CONTENT,
|
||||
margin: {
|
||||
left: 10,
|
||||
right: 50,
|
||||
top: 50,
|
||||
bottom: 10,
|
||||
},
|
||||
widthSpec: LayoutSpec.WRAP_CONTENT,
|
||||
heightSpec: LayoutSpec.EXACTLY,
|
||||
alignment: gravity().center(),
|
||||
},
|
||||
text: `Cell At Line ${idx}`,
|
||||
textAlignment: gravity().center(),
|
||||
textColor: Color.parse("#ffffff"),
|
||||
textSize: 20,
|
||||
})).also(it => {
|
||||
it.gravity = gravity().center()
|
||||
height: 50,
|
||||
bgColor: Color.parse('#00ff00'),
|
||||
}),
|
||||
text({
|
||||
layoutConfig: {
|
||||
widthSpec: LayoutSpec.EXACTLY,
|
||||
heightSpec: LayoutSpec.EXACTLY,
|
||||
alignment: gravity().center(),
|
||||
weight: 1,
|
||||
},
|
||||
text: `Right`,
|
||||
textAlignment: gravity().right(),
|
||||
textColor: Color.parse("#ffffff"),
|
||||
textSize: 20,
|
||||
height: 50,
|
||||
bgColor: Color.parse('#00ffff'),
|
||||
}),
|
||||
]).also(it => {
|
||||
it.layoutConfig = {
|
||||
widthSpec: LayoutSpec.AT_MOST,
|
||||
heightSpec: LayoutSpec.WRAP_CONTENT,
|
||||
alignment: gravity().center(),
|
||||
}
|
||||
it.bgColor = Color.parse('#ffffff')
|
||||
})
|
||||
).also(it => {
|
||||
it.bgColor = Color.parse(colors[idx % colors.length])
|
||||
it.layoutConfig = {
|
||||
widthSpec: LayoutSpec.AT_MOST,
|
||||
@ -51,8 +72,7 @@ class ListPanel extends Panel {
|
||||
it.height = 100
|
||||
it.onClick = () => {
|
||||
log(`Click item at ${idx}`)
|
||||
it.bgColor = Color.parse('#000000')
|
||||
log(`bgcolor is ${Color.parse('#000000').toModel()}`)
|
||||
it.height += 10
|
||||
}
|
||||
})
|
||||
},
|
||||
|
Reference in New Issue
Block a user