CardContent

提供帶標題、右側內容和正文的儀表結構。正文 renderer 會取得扣除標題和邊距後的 contentSize,可據此安排數字、圖形或圖表。

範例

function main() {
  return (
    <CardContent
      title="Speed"
      trailing="GPS"
      renderer={(metrics) => (
        <Text width={metrics.contentSize.width} fontSize={48}>
          78
        </Text>
      )}
    />
  );
}

使用說明

  • renderer 在標題測量後取得 metrics 並回傳正文。使用 contentSize,別猜標題高度。inset 保留標題和邊距;full 使用整張卡片,可能畫到標題背後。
  • 數字尺寸用點;auto 按內容測量,fill 使用父級分配的空間。先設定容器尺寸,再調整子 View;fill 不會創造額外空間,長文字也不能撐開固定父級。

屬性

title?string | View | null

標題文字或 View。

範例""
renderer?(metrics: CardContentMetrics) => ViewContent

使用測量後的標題尺寸建立正文。

範例metrics => <Group/>
children?ViewContent

子檢視內容。

trailing?string | View | null

標題右側的文字或 View。

範例""
contentMode?"inset" | "full"

inset 將內容放在標題下並保留內距;full 提供整張卡片範圍。

範例"inset"
headerBackground?View | null

標題背後的 View;null 不顯示,不作為正文子內容。

範例<Material type="frosted"/>
通用屬性
width?number | "auto" | "fill"

寬度:點數、自動測量或填滿父區域。

範例100
height?number | "auto" | "fill"

高度:點數、自動測量或填滿父區域。

範例80
padding?number

內容內邊距,單位為點。

範例0
x?number

視覺位移,單位為點:x 向右、y 向下,不改變版面佔位。

範例0
y?number

視覺位移,單位為點:x 向右、y 向下,不改變版面佔位。

範例0
transform?ViewTransform

整體視覺變換不改變版面。平移用點,旋轉及傾斜用度,縮放 1 不變,錨點用 0–1。

範例{rotation: 0}
background?Paint

背景填色,接受顏色或漸層;clear 表示透明。

範例"clear"
opacity?number

整個 View 的不透明度:0 完全透明,1 完全不透明。

範例1
cornerRadius?number

圓角半徑,單位為點。

範例0
clipped?boolean

是否裁切超出 View 邊界的內容。

範例false
clip?"rectangle" | "ellipse"

裁切形狀:rectangle 矩形或 ellipse 橢圓;Material 另可用 false 停用。

範例"rectangle"
mask?View | null

透明度遮罩 View,置中顯示且不影響佈局;null 表示不使用遮罩。

範例<Circle width="fill" height="fill" background="white"/>
zIndex?number

同層 View 的繪製順序,數值越大越靠前。

範例0
blur?number

模糊半徑,單位為點;0 不模糊。

範例4
innerShadow?DrawingEffect

特效的顏色、不透明度、模糊半徑及 x/y 位移;距離用點。

範例{color: HDR("black"), opacity: 0.5, radius: 4, x: 0, y: 2}

特效的顏色、不透明度、模糊半徑及 x/y 位移;距離用點。

範例{color: HDR("cyan"), radius: 8, opacity: 0.8}
shadowColor?Color

外部陰影顏色。

範例HDR("black")
shadowOpacity?number

外部陰影不透明度 0–1;0 隱藏陰影。

範例0
shadowRadius?number

外部陰影模糊半徑,單位為點。

範例4
shadowX?number

外部陰影位移,單位為點:x 向右、y 向下。

範例0
shadowY?number

外部陰影位移,單位為點:x 向右、y 向下。

範例2
animations?Animation[]

屬性改變時播放動畫。duration/delay 用秒,from/to 設端點,repeat/autoreverse 控制重複,wrap 設週期。

範例[{property: "opacity", duration: 0.25, curve: "easeInOut"}]
key?string | number

兄弟節點中的穩定識別碼。

組合範例

function main() {
  return (
    <CardContent
      title="Speed"
      trailing={<Symbol name="location.fill" />}
      contentMode="inset"
      renderer={(metrics) => (
        <VStack
          width={metrics.contentSize.width}
          height={metrics.contentSize.height}
          spacing={4}
        >
          <Text fontSize={Math.min(64, metrics.contentSize.height * 0.55)}>
            78
          </Text>
          <Text fontSize={14}>km/h</Text>
        </VStack>
      )}
    />
  );
}

動畫

動畫

widthheightpaddingxyopacitybackgroundcornerRadiusblurshadowColorshadowOpacityshadowRadiusshadowXshadowYtransform.translateXtransform.translateYtransform.scaleXtransform.scaleYtransform.rotationtransform.skewXtransform.skewYtransform.anchorXtransform.anchorY

省略時的行為

下表是經實作核對的省略行為;屬性範例不是預設值。固定效果應明確傳值,尺寸和主題色等依環境變動,不能視為常數。

屬性省略時的行為
contentMode"inset"