feat:fix Android weight props blend error

This commit is contained in:
pengfei.zhou 2019-11-16 17:35:42 +08:00
parent 1b08c227ef
commit b3ef2004fc
3 changed files with 52 additions and 22 deletions

View File

@ -16,6 +16,7 @@
package pub.doric.shader; package pub.doric.shader;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Gravity;
import android.widget.TextView; import android.widget.TextView;
import pub.doric.DoricContext; import pub.doric.DoricContext;
@ -52,7 +53,7 @@ public class TextNode extends ViewNode<TextView> {
view.setTextColor(prop.asNumber().toInt()); view.setTextColor(prop.asNumber().toInt());
break; break;
case "textAlignment": case "textAlignment":
view.setGravity(prop.asNumber().toInt()); view.setGravity(prop.asNumber().toInt() | Gravity.CENTER_VERTICAL);
break; break;
default: default:
super.blend(view, name, prop); super.blend(view, name, prop);

View File

@ -19,6 +19,7 @@ import android.content.Context;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.LinearLayout;
import pub.doric.DoricContext; import pub.doric.DoricContext;
import pub.doric.DoricRegistry; import pub.doric.DoricRegistry;
@ -66,7 +67,7 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
this.mId = id; this.mId = id;
} }
public String getType(){ public String getType() {
return mType; return mType;
} }
@ -93,6 +94,14 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder {
} else { } else {
params = mLayoutParams; 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); mView.setLayoutParams(params);
} }

View File

@ -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 = [ const colors = [
"#f0932b", "#f0932b",
"#eb4d4b", "#eb4d4b",
@ -26,23 +26,44 @@ class ListPanel extends Panel {
list({ list({
itemCount: 1000, itemCount: 1000,
renderItem: (idx: number) => { renderItem: (idx: number) => {
return listItem(text({ return listItem(
layoutConfig: { hlayout([
widthSpec: LayoutSpec.AT_MOST, text({
heightSpec: LayoutSpec.WRAP_CONTENT, layoutConfig: {
margin: { widthSpec: LayoutSpec.WRAP_CONTENT,
left: 10, heightSpec: LayoutSpec.EXACTLY,
right: 50, alignment: gravity().center(),
top: 50, },
bottom: 10, text: `Cell At Line ${idx}`,
}, textAlignment: gravity().center(),
}, textColor: Color.parse("#ffffff"),
text: `Cell At Line ${idx}`, textSize: 20,
textAlignment: gravity().center(), height: 50,
textColor: Color.parse("#ffffff"), bgColor: Color.parse('#00ff00'),
textSize: 20, }),
})).also(it => { text({
it.gravity = gravity().center() 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.bgColor = Color.parse(colors[idx % colors.length])
it.layoutConfig = { it.layoutConfig = {
widthSpec: LayoutSpec.AT_MOST, widthSpec: LayoutSpec.AT_MOST,
@ -51,8 +72,7 @@ class ListPanel extends Panel {
it.height = 100 it.height = 100
it.onClick = () => { it.onClick = () => {
log(`Click item at ${idx}`) log(`Click item at ${idx}`)
it.bgColor = Color.parse('#000000') it.height += 10
log(`bgcolor is ${Color.parse('#000000').toModel()}`)
} }
}) })
}, },