diff --git a/Android/doric/src/main/java/pub/doric/shader/TextNode.java b/Android/doric/src/main/java/pub/doric/shader/TextNode.java index ecdedf60..b83b8d27 100644 --- a/Android/doric/src/main/java/pub/doric/shader/TextNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/TextNode.java @@ -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 { 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); diff --git a/Android/doric/src/main/java/pub/doric/shader/ViewNode.java b/Android/doric/src/main/java/pub/doric/shader/ViewNode.java index 3faae261..b6d2de7a 100644 --- a/Android/doric/src/main/java/pub/doric/shader/ViewNode.java +++ b/Android/doric/src/main/java/pub/doric/shader/ViewNode.java @@ -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 extends DoricContextHolder { this.mId = id; } - public String getType(){ + public String getType() { return mType; } @@ -93,6 +94,14 @@ public abstract class ViewNode 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); } diff --git a/demo/src/ListDemo.ts b/demo/src/ListDemo.ts index 843ab12c..77a692e6 100644 --- a/demo/src/ListDemo.ts +++ b/demo/src/ListDemo.ts @@ -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({ - layoutConfig: { - widthSpec: LayoutSpec.AT_MOST, - heightSpec: LayoutSpec.WRAP_CONTENT, - margin: { - left: 10, - right: 50, - top: 50, - bottom: 10, - }, - }, - text: `Cell At Line ${idx}`, - textAlignment: gravity().center(), - textColor: Color.parse("#ffffff"), - textSize: 20, - })).also(it => { - it.gravity = gravity().center() + return listItem( + hlayout([ + text({ + layoutConfig: { + widthSpec: LayoutSpec.WRAP_CONTENT, + heightSpec: LayoutSpec.EXACTLY, + alignment: gravity().center(), + }, + text: `Cell At Line ${idx}`, + textAlignment: gravity().center(), + textColor: Color.parse("#ffffff"), + textSize: 20, + 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 } }) },